删除mysql中重复数据,仅保留1行
2019-02-13 本文已影响5人
onwingsofsong
尝试了百度搜到的前几个答案,没一个可用。注意:c1,c2是用来判断重复的条件。
DELETE FROM table
WHERE id NOT IN(
SELECT id FROM
(
SELECT MIN(id)AS id
FROM table
GROUP BY c1,c2 HAVING
COUNT(*) > 1
)AS a )
AND id NOT IN(
(SELECT ids FROM
(
SELECT MIN(id)AS ids
FROM table
GROUP BY c1,c2 HAVING
COUNT(*) =1
)AS a1
)
)