T-SQL Specific Syntax problem (Simple no doubt)
- by Yoda
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