面试题:删除数据库中带有重复字段的记录,只保留一条记录

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 awhere (a.peopleId,a.seq) in   (select peopleId,seq from vitae group by peopleId,seq having

猜你喜欢

转载自blog.csdn.net/wangping623/article/details/80532588