RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
mysql删除重复数据
MySQL删除重复数据分为两种情况:
一、以一个字段来唯一确定一条记录,可以用以下SQL来删除:
delete glt_entity_tmp from glt_entity_tmp,(select idd from glt_entity_tmp group by nam having count(*) > 1 ) as t2
where glt_entity_tmp.idd=t2.idd

注意:数据中idd不一致,其它字段信息都一致,如果是一个nam有多于2条重复的记录,要执行多次

二、以二个或以上字段来唯一确定一条记录,可以用以下SQL来删除,但要注意每条记录中必须有第三个字段来唯一确定这条记录(使用max删除)
delete gbi_pd_theme_new_tmp from gbi_pd_theme_new_tmp,(select new_code,the_code,max(the_new_code) as the_new_code from gbi_pd_theme_new_tmp group by new_code,the_code having count(*) > 1) as t2
where gbi_pd_theme_new_tmp.new_code=t2.new_code and gbi_pd_theme_new_tmp.the_code=t2.the_code and gbi_pd_theme_new_tmp.the_new_code=t2.the_new_code

注意:如果是有多于2条重复的记录,要执行多次
因为此例子中每条记录有一个唯一的字段the_new_code,所以可以用max来删除重复记录


分享文章:mysql删除重复数据
分享URL:http://scyingshan.cn/article/pdodhe.html