码迷,mamicode.com
首页 > 数据库 > 详细

mysql 删除重复记录语句

时间:2016-11-17 01:22:03      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:条件   sid   osi   数据   bsp   group   not   new   记录   

 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
)

mysql 删除重复记录语句

标签:条件   sid   osi   数据   bsp   group   not   new   记录   

原文地址:http://www.cnblogs.com/jackspider/p/6071740.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!