欢迎来到欣怡建站!我们致力于提供优质的网站建站服务
注册

织梦网站MYSQL查询重复记录的方法

相关案例演示

1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断

select * from people   

where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) 

2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录  

delete from people   

where peopleId in (select peopleId from people group by peopleId   having count(peopleId) > 1)   

and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)   

3、查找表中多余的重复记录(多个字段)

select * from vitae a   

where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)   

4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录

delete from vitae a   

where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)   

and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)   

5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录

select * from vitae a   

where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)   

and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)   

作者:欣怡建站 挑错 时间:2020-03-14 09:39
首先声明,只要是我们的vip会员所有源码均可以免费下载,不做任何限制
☉本站的源码不会像其它下载站一样植入大量的广告。为了更好的用户体验以后坚持不打水印
☉本站只提供精品源码,源码在于可用,不在多!!希望在这里找到你合适的。
☉本站提供的整站程序,均带数据及演示地址。可以在任一源码详情页查看演示地址
☉本站所有资源(包括源码、模板、素材、特效等)仅供学习与参考,请勿用于商业用途。
☉如有其他问题,请加网站客服QQ(984818011)进行交流。
相关教程
在线客服