Skip to content

Instantly share code, notes, and snippets.

@cruzer45
Created May 20, 2016 17:36
Show Gist options
  • Select an option

  • Save cruzer45/dde062037be988d5f63a86f11859179b to your computer and use it in GitHub Desktop.

Select an option

Save cruzer45/dde062037be988d5f63a86f11859179b to your computer and use it in GitHub Desktop.
Postgres Delete duplicate rows
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