mysql之删除重复数据详解数据库

//删除id重复的数据,适合id是手工主键
delete person as a from person as a,
(
    select *,min(id) from person group by id having count(1) > 1
) as b
where a.id = b.id

                  

//查找name重复的,并且除掉id最小的那个
delete tb_person as a from tb_person as a,

(

select *,min(id) from tb_person  group by name having count(1) > 1

) as b

 where a.name = b.name and a.id > b.id;

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/4855.html

(0)
上一篇 2021年7月16日
下一篇 2021年7月16日

相关推荐

发表回复

登录后才能评论