MYSQL 删除重复数据并保留ID最小的一条

  • A+
所属分类:个人原创
DELETE FROM mtk
WHERE
`code` IN (SELECT
*
FROM
(SELECT
`code`
FROM
mtk
GROUP BY `code`
HAVING COUNT(`code`) > 1) t1)
AND id NOT IN (SELECT
*
FROM
(SELECT
MIN(id)
FROM
mtk
GROUP BY `code`
HAVING COUNT(`code`) > 1) t2)

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

请输入验证码 *