Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Deleting dup emails

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2011-06-07 : 16:27:57
I have a table that has an ID(Unique),email
I want to delete all duplicate emails. How do I do this?

Dave
Helixpoint Web Development
http://www.helixpoint.com

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-06-07 : 17:18:31
There are a bunch of ways, here is one:
DELETE A
FROM
(
SELECT *, ROW_NUMBER() OVER (PARTITION BY email ORDER BY ID) AS RowNum
FROM <Tablename>
) AS A
WHERE RowNum > 1
Go to Top of Page
   

- Advertisement -