请知悉:本文最近一次更新为 10年 前,文中内容可能已经过时。

1.查某一列(或多列)的重复值(只可以查出重复记录的值,不能查出整个记录的信息)
例如:查找stuid,stuname重复的记录

select stuid,stuname from stuinfo
group by stuid,stuname
having(count(*))>1

2.查某一列有重复值的记录(此方法查出的是所有重复的记录,如果有两条记录重复的,就查出两条)
例如:查找stuid重复的记录

select * from stuinfo
where stuid in (
select stuid from stuinfo
group by stuid
having(count(*))>1
)

3.查某一列有重复值的记录(只显示多余的记录,也就是说如果有三条记录重复的,就显示两条)
前提:需有一个不重复的列,此示例为recno。
例如:查找stuid重复的记录

select * from stuinfo s1
where recno not in (
select max(recno) from stuinfo s2
where s1.stuid=s2.stuid)

以上内容整理自:https://www.knowsky.com/397948.html

示例:

select * from Cust_Linker
where LinkEmail in (
select LinkEmail from Cust_Linker group by LinkEmail having(count(*))>1 and LinkEmail<>''
)
or
LinkTel in (
select LinkTel from Cust_Linker group by LinkTel having(count(*))>1 and linktel<>''
)

如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《MSSQL-SQL Server数据库查找重复记录》相关的博文:


留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌