Created
January 11, 2013 11:12
-
-
Save ankitnetwork18/4509926 to your computer and use it in GitHub Desktop.
mysql: delete all duplicate records from 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
DELETE n1 FROM names n1, names n2 WHERE n1.id > n2.id AND n1.name = n2.name | |
if you want to keep the row with the lowest id value OR | |
DELETE n1 FROM names n1, names n2 WHERE n1.id < n2.id AND n1.name = n2.name | |
DELETE FROM table_name | |
where column_name in( | |
SELECT column_name | |
FROM ( | |
select column_name | |
FROM table_name | |
GROUP BY column_A, column_B, column_C, ... | |
having COUNT(*)>1)temp | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment