mysql 删除重复记录语句

mysql 根据条件删除重复记录 只保留最小id的重复数据

DELETE
FROM
news
WHERE
news_id IN (
SELECT
a.news_id
FROM
(
SELECT
news_id
FROM
news
WHERE
flag = 1
GROUP BY
news_id
HAVING
count(news_id) > 1
) a
)
AND posid NOT IN (
SELECT
b.posid from (
SELECT
min(posid) as posid
FROM
news
where flag=1
GROUP BY
news_id
HAVING
count(news_id) > 1
) b
)

上一篇:sql查询重复记录、删除重复记录方法大全


下一篇:mysql 数据表中查找、删除重复记录