T-SQL Specific Syntax problem (Simple no doubt)
Posted
by Yoda
on Stack Overflow
See other posts from Stack Overflow
or by Yoda
Published on 2010-04-23T09:02:44Z
Indexed on
2010/04/23
9:13 UTC
Read the original article
Hit count: 176
t-sql
|sql-server
Hi guys,
I have an issue with a query I'm trying to run on some data, I guess the place to start is to describe the data.
Ok so I have a list of email addresses, each email address has a unique ID and an account ID
Also in my tables I have a set number which auto incrememnts, this will allow me to target duplicate email addresses
What I need to do is something like this.
Insert into duplicates
(EMAIL,ACCOUNTID,ID)
SELECT Email,AccountID,ID
FROM EmailAddresses
Group by Email,AccountID
Having Count(email)>1
Order by AccountID, Email
So essentially I want to select all duplicate email addresses and insert them (and their relative fields) into a new table broken down by accountID so I can run some further querys on it.
I have been battling with this for way too long and could just use a fresh perspective.
Cheers in advance
© Stack Overflow or respective owner