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

2024-11-09 15:57:28
推荐回答(1个)
回答1:

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