Skip to content

Instantly share code, notes, and snippets.

@Azerothian
Created September 16, 2015 01:58
Show Gist options
  • Save Azerothian/6e5e0243c5c6dd37fee4 to your computer and use it in GitHub Desktop.
Save Azerothian/6e5e0243c5c6dd37fee4 to your computer and use it in GitHub Desktop.
How to delete rows that are duplicates over a set of columns, keeping only the one with the lowest ID.
DELETE FROM tablename
WHERE id IN (SELECT id
FROM (SELECT id,
ROW_NUMBER() OVER (partition BY column1, column2, column3 ORDER BY id) AS rnum
FROM tablename) t
WHERE t.rnum > 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment