一个表中有重复记录如何用SQL语句查询出来。。。?

2022-08-06 社会 96阅读

select * from tablename where 重复字段1 in (select 重复字段1 from tablename group by 重复字段1,重复字段2 having count(*)>1)。

SQL重复记录查询方法:

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

声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com