mysql 删除重复数据保留只保留一条

SELECT * FROM
(SELECT addTime FROM motorcade.car_msg_info GROUP BY addTime HAVING COUNT(addTime) > 1)
AS b)
AND ID NOT IN (SELECT * FROM
(SELECT MIN(ID) FROM motorcade.car_msg_info GROUP BY addTime HAVING COUNT(addTime) > 1)
AS c)

 delete from people where   peopleName in (select peopleName    from people group by peopleName      having count(peopleName) > 1) and   peopleId not in (select min(peopleId) from people group by peopleName     having count(peopleName)>1)

 

MIN(ID)表示保留ID最小的一条 换成MAX可以保留最新的一条

addTime代表重复数据  

posted @ 2016-11-07 11:37  每天多帅一点点  阅读(393)  评论(0编辑  收藏  举报