Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davidsheardown/781374d7e00f587e88aac942caf609e2 to your computer and use it in GitHub Desktop.
Save davidsheardown/781374d7e00f587e88aac942caf609e2 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