Skip to content

Instantly share code, notes, and snippets.

@coderdiaz
Last active August 29, 2015 14:18
Show Gist options
  • Save coderdiaz/e0578e133dcc5c92059e to your computer and use it in GitHub Desktop.
Save coderdiaz/e0578e133dcc5c92059e to your computer and use it in GitHub Desktop.
How to delete duplicate rows with MySQL
DELETE n1
FROM table1 n1, table1 n2
WHERE n1.id > n2.id
AND n1.id_name = n2.id_name;
/*
* With this query you can
* delete the duplicate rows in one table (table1)
* ´WHERE n1.id > n2.id´ with this line you can keep the first row
* if you want keep the second row you need use ´WHERE n1.id < n2.id´
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment