码迷,mamicode.com
首页 > 数据库 > 详细

mysql 查找除id外其他重复的字段数据

时间:2017-06-01 13:16:30      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:重复   name   group by   pre   test   word   删除   keyword   logs   

如表 test1 有多个重复的字段

技术分享

其中有些数据完全重复是错误的数据,我们要把他找出来,然后删除掉

select * from test1 a where (a.phone,a.name) in (

select phone,name from test1 group by phone,name having count(*)>1

) and id not in (

select max(id) from test1 group by phone,name having count(*)>1

);

结果

技术分享

然后就可以用php或其他语言来删除这些 id 了

或者 

把前面的那个select换成

delete 

delete from test1 where (a.phone,a.namein (

select phone,name from test1 group by phone,name having count(*)>1

) and id not in (

select max(id) from test1 group by phone,name having count(*)>1

);

mysql 查找除id外其他重复的字段数据

标签:重复   name   group by   pre   test   word   删除   keyword   logs   

原文地址:http://www.cnblogs.com/wtcl/p/6928168.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!