http://www.hanyu123.cn/html/c61/6790.html
一、查某一列(或多列)的重復值。(只可以查出重復記錄的值,不能查出整個記錄的信息)
例如:查找stuid,stuname重復的記錄:
- select stuid,stuname from stuinfo
- group by stuid,stuname
- having(count(*))>1
二、查某一列有重復值的記錄。(此方法查出的是所有重復的記錄,如果有兩條記錄重復的,就查出兩條)
例如:查找stuid重復的記錄:
- select * from stuinfo
- where stuid in (
- select stuid from stuinfo
- group by stuid
- having(count(*))>1
- )
三、查某一列有重復值的記錄。(只顯示多余的記錄,也就是說如果有三條記錄重復的,就顯示兩條)
前提:需有一個不重復的列,此示例為recno。例如:查找stuid重復的記錄:
- select * from stuinfo s1
- where recno not in (
- select max(recno) from stuinfo s2
- where s1.stuid=s2.stuid
?