开发者

PHP/MySQL - update rows with duplicate entries

开发者 https://www.devze.com 2023-02-08 04:28 出处:网络
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 u

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
0

精彩评论

暂无评论...
验证码 换一张
取 消