Last active
July 2, 2019 11:29
-
-
Save t27/91d340515045c8c62e6b00cc0aec64d2 to your computer and use it in GitHub Desktop.
Find rows in a table that have duplicate values for columns x,y,z,w. Also optionally aggregate another column.
This file contains hidden or 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
--Postgres | |
--just find duplicates | |
select col1,col2,col3,col4,col5,count(*) from my_table group by 1,2,3,4,5,6 HAVING count(*)>1 | |
-- find duplicates and aggregate Ids, so that you can save one and delete the rest ('id' is a column in the table) | |
select col1,col2,col3,col4,col5,count(*), string_agg(id::character varying, ';' order by sign_code) from my_table group by 1,2,3,4,5,6 HAVING count(*)>1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment