Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save morbidcamel101/826f263a22719559a884dc32b69daa8d to your computer and use it in GitHub Desktop.
Save morbidcamel101/826f263a22719559a884dc32b69daa8d to your computer and use it in GitHub Desktop.
MS SQL (CTE) Remove Duplicate Rows
;WITH CTE AS(
SELECT field_to_identify_duplicate,
RN = ROW_NUMBER()OVER(PARTITION BY field_to_identify_duplicate ORDER BY field_to_identify_duplicate)
FROM table_with_duplicates
)
DELETE FROM CTE WHERE RN > 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment