表数值如下
 
     a        b         c
1    11       1         01
2    12       1         01
3    12       2         01
4    13       1         01
5    13       2         02现在要取出table表里面 a列 和 c列重复的  比如上面 a列 12 对应 c列两个01取出来的目的是不允许 a列和c列有重复的值.

解决方案 »

  1.   

    select * from tb a where not exists(select 1 from tb where a.a = a and a.c = c)
      

  2.   


    select * from tb a where not exists(select 1 from tb where a.a = a and a.c = c and a.id >id) 
      

  3.   

    select * from a aa where exists(select 1 from a where a=aa.a and c=aa.c and id<>aa.id)
      

  4.   

    select a,c from tb group by a,c having count(1)>1
      

  5.   

    select a.* from tb a join (select a,c from tb group by a,c having count(1)>1) b
    on a.a=b.a and a.c=b.c
      

  6.   

    select * from @table t 
    where exists (select * from @table where a = t.a and c = t.c and id <> t.id )