首页 > 代码库 > mysql 删除重复数据保留只保留一条

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)

 

 

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

addTime代表重复数据  

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