删除 MySQL 中除重复行之外的所有重复行? [复制]
用户表有 5 条记录,其中包含重复的 [email protected] 电子邮件
搜索会返回 Users 表中的重复电子邮件:
SELECT *, COUNT(email) FROM users
GROUP BY email
HAVING COUNT(email) > 1;
使用 DELETE JOIN 语句删除重复行
DELETE table1 FROM users table1
INNER JOIN users table2
WHERE table1.id < table2.id AND table1.email = table2.email
结果