select *
          from a t
         where exists (select 1
                  from a 
                 where t.b=2
                    or t.b = 3)
这个语句啥意思呀?
里面的查询查出来的都是1,外面的怎么可能有符合的呢?

解决方案 »

  1.   

    exists即可,不关心是什么值,你写2也一样
      

  2.   


    无效  根本就没有匹配的
    select *
      from a t
      where t.b in(2,3)
      

  3.   

    SQL> create table temp(id number,b number);
     
    Table created
     
    SQL> insert into temp values(1,2)
      2  ;
     
    1 row inserted
     
    SQL> insert into temp values(1,3);
     
    1 row inserted
     
    SQL> insert into temp values(1,4);
     
    1 row inserted
     
    SQL> insert into temp values(1,1);
     
    1 row inserted
    SQL> select * from temp t where exists(select 1 from temp where t.b = 2 or t.b = 3);
     
            ID          B
    ---------- ----------
             1          2
             1          3
     
    SQL>  
    exists (select 1
    from a 
    where t.b=2
    or t.b = 3)
    是否存在的意思,存在即为真,否则为假
      

  4.   


    内层的 select 1 中的1可以是任意的  他只返回true or false  只要外层有跟里层的匹配就TRUE 相反则false
      

  5.   


    这个不就是在查询 select * from a where a.b in (2,3);??
      

  6.   

    干嘛要用exists哦,select * from a where a.b in (2,3);这个多好啊
      

  7.   

    匹配项少时(10个以下),in为首选,多则exists
      

  8.   

    exist和not exist子句就是用来判断
    当子句满足或不满足输出子句外的查询语句。