Created
May 24, 2019 15:32
-
-
Save dncpax/df64dd4fc67f1d846ba10e5a6d3ec335 to your computer and use it in GitHub Desktop.
postgresql - 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, | |
ROW_NUMBER() OVER(PARTITION BY column1, column2 ORDER BY id asc) AS Row | |
FROM tbl | |
) dups | |
where | |
dups.Row > 1 |
Another possibility I like:
select objectid, count(*)
from table where condition=value
group by objectid
HAVING count(*) > 1
Simple to read and remember...
original here: https://stackoverflow.com/questions/50805439/postgresql-fastest-way-to-get-duplicates
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
original here: https://stackoverflow.com/questions/14471179/find-duplicate-rows-with-postgresql/14471928#14471928
best alternative yet for me, in readability and performance, because it supports several fields and lists duplicate records except the "original" (dups.Row=1), so you can easily identify or delete the duplicates.