Skip to content

Instantly share code, notes, and snippets.

@lastday154
Created November 22, 2017 08:30
Show Gist options
  • Select an option

  • Save lastday154/41d51d94a1a19fb5480a1a0ddde8f548 to your computer and use it in GitHub Desktop.

Select an option

Save lastday154/41d51d94a1a19fb5480a1a0ddde8f548 to your computer and use it in GitHub Desktop.
Remove duplicate rows mysql
// 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