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

解决方案 »

  1.   

    exists意思是存在值,不关心值的具体数值
      

  2.   

    EXISTS Condition An EXISTS condition tests for existence of rows in a subquery.
    Description of the illustration exists_condition.gif
    Table 7-11 shows the EXISTS condition.Table 7-11 EXISTS Condition Type of Condition Operation Example 
    EXISTS 
     TRUE if a subquery returns at least one row.
     SELECT department_id
      FROM departments d
      WHERE EXISTS
      (SELECT * FROM employees e
        WHERE d.department_id 
        = e.department_id);
     
      

  3.   

    也就是说,不管里面select查出的是什么,都是无所谓的?
      

  4.   

    EXISTS, TRUE if a subquery returns at least one row.
    也就是说只要内层返回至少一行,exists就成立,为true
    排版乱了点,将就看吧
      

  5.   

    对,就是这个道理.只要子查询的记录数大于等于1就可以了.没有记录才为FALSE
      

  6.   

    甚至你里面写null也没关系.
    SQL> SELECT 1 FROM dual WHERE EXISTS (SELECT NULL FROM dual);
     
             1
    ----------
             1
     
    SQL> 
      

  7.   

    哦,谢谢明白了。有数据的话返回True,没有数据返回false