查找数据库中重复值

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

SELECT 新库编号
FROM usedcar_detail
GROUP BY 新库编号
HAVING (COUNT(*) > 1)
ORDER BY 新库编号

2.查某一列有重复值的记录(此方法查出的是所有重复的记录,如果有两条记录重复的,就查出两条)
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.cnblogs.com/shuyu/p/1702799.html