select * from cms.dept d where dept_id = all(
    select dept_id from cms.emp e where  dept_id = d.dept_id and 1 = 2)请问上面的查询结果为什么是cms.dept的内容?

解决方案 »

  1.   

    select * from cms.dept  ------你查询的就是这个表select * from cms.dept d where dept_id = all(
      select dept_id from cms.emp e where dept_id = d.dept_id and 1 = 2)========select * from cms.dept d where dept_id in(
      select dept_id from cms.emp e where dept_id = d.dept_id and 1 = 2)
      

  2.   

    主表cms.dept,all后边是个子查询。
      

  3.   


    上面的语句查询应该是个空吧,因为后面有 and 1 =2
    可是我的问题的那个不会,不知道是为什么
      

  4.   

    ALL的比较规则是
    1、对于有效表达式,比较表达式是否都为true
       如 col1 = all(select col from table)  --假设table里面有值 'A','B'
          那么会产生两个表达式 (col1,'A') 和 (col1,'B'),当这两个表达式全是true的时候
           col1 = all(select col from table) 成立。2、对于无效表达式 如:col1 = all(select col from table where 1=2)
       因为子查询里面查询的结果什么都没有,相当于这个条件不起作用
       ALL运算就会把这个查询当做 外联来看, 主表就是外面的表,因为是外连接,所以一定是能查出主表的值得。ANY和ALL正好相反,而且多了一个条件,就是表达式必须为有效表达式
    如果把你的sql种的ALL换成ANY,就不会有结果查出,因为ANY遇到无效表达式返回结果为false
      

  5.   

    在学数据库系统概论当时就有说明= all一般没有实际意义
    一般有意义的any all都可以转为in exists
    所以一般不用Any all