Skip to content

Instantly share code, notes, and snippets.

@ankitnetwork18
Created January 11, 2013 11:12
Show Gist options
  • Save ankitnetwork18/4509926 to your computer and use it in GitHub Desktop.
Save ankitnetwork18/4509926 to your computer and use it in GitHub Desktop.
mysql: delete all duplicate records from table
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