方法一:通过学号和身份证字段来查询(数据库执行效率高,推荐)
SELECT *
FROM student AS A
WHERE (Sno IN (SELECT Sno FROM student AS B WHERE A.ID <> B.ID))
方法二:只通过学号字段来查询(数据库执行效率低,不推荐)
SELECT *
FROM student AS A
WHERE (SELECT COUNT(*) FROM student WHERE Sno=A.Sno)>1
从运行结果来看,方法一和方法二相同,但是执行效率完全不同,方法一执行一万多条数据只需要几秒钟即可,方法二则需要好几分钟,而且还有死机现象。
参照:http://database.51cto.com/art/201011/235159.htm