Created
October 17, 2011 03:57
-
-
Save FrancoisConstant/1291912 to your computer and use it in GitHub Desktop.
Find and remove duplicates in table - keeps only distinct values (without a temp table)
This file contains 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
SELECT people_user.* | |
FROM people_user | |
LEFT OUTER JOIN ( | |
SELECT MIN(user_id) as MinId, email | |
FROM people_user | |
GROUP BY email | |
) as KeepRows ON | |
people_user.user_id = KeepRows.MinId | |
WHERE | |
KeepRows.MinId IS NULL; | |
DELETE people_user | |
FROM people_user | |
LEFT OUTER JOIN ( | |
SELECT MIN(user_id) as MinId, email | |
FROM people_user | |
GROUP BY email | |
) as KeepRows ON | |
people_user.user_id = KeepRows.MinId | |
WHERE | |
KeepRows.MinId IS NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment