Skip to content

Instantly share code, notes, and snippets.

@selfish
Created November 15, 2015 16:07
Show Gist options
  • Select an option

  • Save selfish/8a6129e281b2b723a6b7 to your computer and use it in GitHub Desktop.

Select an option

Save selfish/8a6129e281b2b723a6b7 to your computer and use it in GitHub Desktop.
Delete duplicates MySQL table, leaving one row for each duplicate group
DELETE `t1`
FROM `table` `t1`
INNER JOIN `table` `t2`
ON `t1`.`dup_col1` = `t2`.`dup_col1`
AND `t1`.`dup_col2` = `t2`.`dup_col2`
# AND...
WHERE `t1`.`primary_key` > `t2`.`primary_key`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment