Skip to content

Instantly share code, notes, and snippets.

@jazz7381
Last active December 24, 2021 07:08
Show Gist options
  • Save jazz7381/8ca331b581c6e5c59a7f5ab1a6172476 to your computer and use it in GitHub Desktop.
Save jazz7381/8ca331b581c6e5c59a7f5ab1a6172476 to your computer and use it in GitHub Desktop.
Remove duplicate data and leave data with less ID from PostgreSQL
DELETE FROM tablename
WHERE id IN (SELECT id
FROM (SELECT id,
ROW_NUMBER() OVER (partition BY column1, column2 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