Created
March 14, 2013 22:30
-
-
Save jaguire/5165829 to your computer and use it in GitHub Desktop.
Delete duplicates for ms sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- FIELD is the unique field to find duplicates on | |
delete TABLENAME | |
from TABLENAME | |
left outer join ( | |
select min([Key]) as [Key], FIELD | |
from TABLENAME | |
group by FIELD | |
) as temp on | |
TABLENAME.[Key] = temp.[Key] | |
where temp.[Key] is null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment