Skip to content

Instantly share code, notes, and snippets.

@dncpax
Created May 24, 2019 15:32
Show Gist options
  • Save dncpax/df64dd4fc67f1d846ba10e5a6d3ec335 to your computer and use it in GitHub Desktop.
Save dncpax/df64dd4fc67f1d846ba10e5a6d3ec335 to your computer and use it in GitHub Desktop.
postgresql - find duplicates
select * from (
SELECT id,
ROW_NUMBER() OVER(PARTITION BY column1, column2 ORDER BY id asc) AS Row
FROM tbl
) dups
where
dups.Row > 1
@dncpax
Copy link
Author

dncpax commented May 24, 2019

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