Created
November 22, 2017 08:30
-
-
Save lastday154/41d51d94a1a19fb5480a1a0ddde8f548 to your computer and use it in GitHub Desktop.
Remove duplicate rows 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 With temp table | |
| CREATE TABLE temp_users AS | |
| SELECT * FROM users GROUP BY user_name; | |
| DROP TABLE users; | |
| RENAME TABLE temp_users TO users; | |
| // delete and keep lower id | |
| DELETE u1 FROM users u1, users u2 | |
| WHERE u1.user_name = u2.user_name | |
| AND u1.id > u2.id; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment