Last active
August 29, 2015 14:18
-
-
Save coderdiaz/e0578e133dcc5c92059e to your computer and use it in GitHub Desktop.
How to delete duplicate rows with MySQL
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 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