mysql数据库去除重复数据的方法:1、查询需要删除的记录,会保留一条记录;2、删除重复记录,只保留一条记录,代码为【delete a from test1 a, (...)as bid from test1 c where..】。
mysql数据库去除重复数据的方法:
1、查询需要删除的记录,会保留一条记录。
1
select a.id,a.subject,a.RECEIVER from test1 a left join (select c.subject,c.RECEIVER ,max(c.id) asbid from test1 c where status=0 GROUP BY RECEIVER,SUBJECT having count(1) >1) b on a.id< b.bid where a.subject=b.subject anda.RECEIVER = b.RECEIVER anda.id < b.bid
2、删除重复记录,只保留一条记录。注意,subject,RECEIVER 要索引,否则会很慢的。
1
deletea from test1 a, (select c.subject,c.RECEIVER ,max(c.id) asbid from test1 c where status=0 GROUP BY RECEIVER,SUBJECT having count(1) >1) b where a.subject=b.subject anda.RECEIVER = b.RECEIVER anda.id < b.bid;
3、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
1
select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)