由于种种原因,不能够使用exists.请问: 
select table1.* from table1 where exists (select 1 from table2 where table1.A=table2.A and table1.B=table2.B and table2.C<>'N')
如何转化成非exists语句?谢谢。

解决方案 »

  1.   

    为什么要转?exists的性能优于in?
    select table1.* from table1 where exists (A,b) in (select a,b from table2 where table2.C <>'N')
      

  2.   

    select C.* --except C.sign
           (    
    select table1.*,table2.A as sign
      from table1,table2
     where table1.A = table2.A
       and table1.B = table2.B
       and table2.C <> 'N' 
           )C
     where C.sign is not null     
      

  3.   

    select table1.* from table1 where not exists (select 1 from table2 where table1.A<>table2.A or table1.B<>table2.B or table2.C ='N')
      

  4.   

    select table1.* from table1 where in
     (select 1 from table2 where table1.A=table2.A and table1.B=table2.B and table2.C <>'N') 
      

  5.   

    in和exists可以互相转换,但是一般exists效率较高。
      

  6.   

    可能有些大虾理解错了我的意思, 我是想把顶楼的那条sql转化成不含exists的语句。
    因为某些特定环境不支持exists,希望大家能理解。
    and楼上的好像都行不通(或者语法有错,或者结果不等价), 希望各位再给我一些建议。1楼的gg能这么写吗?
      

  7.   

    select a.* from table1 a,table2 b where a.A<>b.A and a.B<>b.B and b.C <>'N'