当前位置:Gxlcms > 数据库问题 > SQL Server 数据库查找重复记录的几种方法

SQL Server 数据库查找重复记录的几种方法

时间:2021-07-01 10:21:17 帮助过:14人阅读

  • group by stuidstuname
  • having(count(*))>1
  • 二、查某一列有重复值的记录。(此方法查出的是所有重复的记录,如果有两条记录重复的,就查出两条)

    例如:查找stuid重复的记录:

    1. select * from stuinfo
    2. where stuid in (
    3. select stuid from stuinfo
    4. group by stuid
    5. having(count(*))>1
    6. )

    三、查某一列有重复值的记录。(只显示多余的记录,也就是说如果有三条记录重复的,就显示两条)

    前提:需有一个不重复的列,此示例为recno。例如:查找stuid重复的记录:

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

     

    SQL Server 数据库查找重复记录的几种方法

    标签:

    人气教程排行