Skip to content

Instantly share code, notes, and snippets.

@harmo
Last active December 18, 2016 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harmo/24ac83798f90d0e4581e to your computer and use it in GitHub Desktop.
Save harmo/24ac83798f90d0e4581e to your computer and use it in GitHub Desktop.
Postgresql request to find duplicates
SELECT * FROM (
SELECT id[, other_fields…] ROW_NUMBER() OVER(PARTITION BY <field to search duplicates>) AS row
FROM <table>
) duplicates
WHERE duplicates.row > 1;
-------------------------------------------------------------------------------
SELECT <field to search duplicates>, COUNT(*) FROM <table> GROUP BY <field to search duplicates> HAVING COUNT(*) > 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment