Skip to content

Instantly share code, notes, and snippets.

@jaguire
Created March 14, 2013 22:30
Show Gist options
  • Save jaguire/5165829 to your computer and use it in GitHub Desktop.
Save jaguire/5165829 to your computer and use it in GitHub Desktop.
Delete duplicates for ms sql
-- 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