有一个表,两列id,name,没有主建标识列,现在要查出id 相同的列,sql语句要怎样写

解决方案 »

  1.   

    SELECT * FROM TB T WHERE EXISTS(SELECT 1 FROM TB WHERE ID=T.ID)
      

  2.   

    select ID
    from tb 
    group by ID 
    having COUNT(id)>1
      

  3.   

    select id
    from TB
    group by id 
    having count(*) >1
      

  4.   

    select [id],[name] from tb a 
    where exists(select 1 from tb b where a.id=b.id and a.name<>b.name)
      

  5.   

    select id from tb group by id having count(1) > 1select t.* from tb t where id in (select id from tb group by id having count(1) > 1)
      

  6.   

    select *
    from tb t 
    where exists(select ID from tb where id=t.id group by id having count(1)>1 )
      

  7.   

    select ID
    from tb 
    group by ID 
    having COUNT(id)>1
    这种才是正确的
      

  8.   

    是有误全查出来了,呵呵,要加个NAME<>T.NAME得看数据来,还是小麦他们的那样比较保险,完全重复都能查的
      

  9.   

    select t.* from tb t where id in (select id from tb group by id having count(1) > 1)