Last active
August 29, 2015 14:02
-
-
Save lv10/d9a94f6a949e65a9323a to your computer and use it in GitHub Desktop.
Delete duplicates from a table without primary key SQL
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
DELETE FROM claim_rates | |
WHERE ctid IN (SELECT | |
ctid | |
FROM (SELECT | |
ctid, | |
ROW_NUMBER() | |
OVER ( | |
PARTITION BY claim_tag, rate_type, pricing_record_id | |
ORDER BY claim_tag, rate_type, pricing_record_id) AS rnum | |
FROM claim_rates) t | |
WHERE t.rnum > 1); | |
Documentation here: | |
http://wiki.postgresql.org/wiki/Deleting_duplicates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment