PHP/MySQL - update rows with duplicate entries
I have a database(about 3 million records) which has multiple/duplicate re开发者_Go百科cords with the same "email" in database and I would like to leave a single row with its default status(0) and update "status=5" for the rest of duplicates. Please note that not all the records have duplicates. The email addresses are stored encoded in base64.
UPDATE tbl
JOIN (
SELECT email, MIN(ID) minID
FROM tbl
GROUP BY email
HAVING COUNT(*) > 1) t2 ON tbl.email = t2.email AND tbl.id != t2.minID
SET tbl.status = 5
精彩评论