sqlserver查询重复记录
1.查询某一列或多列的重复记录,只能查出重复的值,不能列出整条记录的信息
select id,name from tb
groupby id,name
having(count(*))>1
2.查询某一列重复的记录,并列出全部
select*from tb
where id in (
select stuid from stuinfo
groupby stuid
having(count(*))>1
)
3.查询某一列重复的记录,列出多余的记录,比如重复三条,列出多余的两条
前提:需要有一个不重复的列,例如下例中的recno,重复的是stuid
select*from stuinfo s1
where recno notin (
selectmax(recno) from stuinfo s2
where s1.stuid=s2.stuid
浙公网安备 33010602011771号