当前位置:Gxlcms > 数据库问题 > mysql 去除表中重复的数据,保留id最小的数据信息

mysql 去除表中重复的数据,保留id最小的数据信息

时间:2021-07-01 10:21:17 帮助过:26人阅读

-- 笨重方法
delete from 
	tb_person 
WHERE
	id NOT IN (  select id from (SELECT min(id) id FROM tb_person GROUP BY email  having count(1) > 1)  tm)
	and email in ( select email from ( SELECT email FROM tb_person GROUP BY email  having count(1) > 1)tm)
-- 获取最小id,排除id信息进行删除 DELETE from Person Where Id not in ( Select MIN(Id) as Id From Person Group by Email )

  

mysql 去除表中重复的数据,保留id最小的数据信息

标签:select   重复   group   去除   class   and   email   mail   count   

人气教程排行