//显示重复的所有条
SELECT * FROM 表名
WHERE (字段1,字段2,...)
IN (SELECT 字段1,字段2,...FROM 表名 GROUP BY 字段1,字段2,... HAVING COUNT(*)>1)
//只显示重复中的一条
SELECT * FROM 表名 GROUP BY CONCAT(字段1,字段2,...) HAVING COUNT(*)>1
//删除重复数据(保留ID最小的一条)
DELETE FROM 表名
WHERE (字段1,字段2,...)
IN (SELECT 字段1,字段2,... FROM
(SELECT 字段1,字段2,... FROM 表名 GROUP BY 字段1,字段2,... HAVING COUNT(*)>1) AS b
)
AND Id NOT IN (SELECT id AS id FROM
(SELECT MIN(Id) AS id FROM 表名 GROUP BY 字段1,字段2,... HAVING COUNT(*)>1) AS c
)
注意:在删除重复数据语句中加深的部分,from后面需要重新套一层查询语句,负责报错。