Created
May 29, 2014 09:52
-
-
Save chanmix51/dc44895e0490c1cd756a to your computer and use it in GitHub Desktop.
Remove duplicate rows from a table
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
with | |
dup_id as (select id, count(*) from school group by id having count(*) > 1), | |
del_dup as (delete from only school using dup_id where school.id = dup_id.id returning school.*) | |
insert into school select distinct on (id) del_dup.* from del_dup order by del_dup.id returning *; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment