龙空技术网

sql 如何查询一个表中某字段的重复记录

咸鱼会开发 329

前言:

此刻大家对“sql查询不重复的记录”都比较关怀,小伙伴们都想要知道一些“sql查询不重复的记录”的相关知识。那么小编同时在网上收集了一些对于“sql查询不重复的记录””的相关文章,希望兄弟们能喜欢,小伙伴们快快来了解一下吧!

select   a.*   from   clist   a,(  	select   cemail   from   clist   	  group   by   cemail  having   count(*)>1)   as   b  where   a.cemail=b.cemail  

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

select * from plistwhere pId in (  	select   pid from   plist    	group by   pid having count(pid) > 1)

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

delete from plistwhere pid in (  	select   pid from plist   	group by   pid   having count(pid) > 1)and rowid not in (    select min(rowid) from  plist 		group by pid     having count(pid)>1)

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

select * from vlist awhere (a.pid,a.seq) in   (  		select pid,seq from vlist   		group by pid,seq   		having  count(*) > 1)

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

delete from vlist awhere (a.pid,a.seq) in   (  		select pid,seq from vlist   group by pid,seq   having   count(*) > 1)and rowid not in (  	select min(rowid) from vlist 		group by pid,seq 		having count(*)>1)

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

select * from vlist awhere (a.pid,a.seq) in   (  		select pid,seq   from vlist   group by pid,seq   having  count(*) > 1)and rowid not in (  		select min(rowid) from   vlist      group by pid,seq      having count(*)>1)

标签: #sql查询不重复的记录