Last active
December 18, 2016 09:26
-
-
Save harmo/24ac83798f90d0e4581e to your computer and use it in GitHub Desktop.
Postgresql request to find duplicates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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