请问各位高手,以下两条语句在相同的环境下查询出来为什么是完全不一样的结果?帮我理解下!谢了!    select * from t2 a where not exists(select 1 from t1,t2 where t1.n>=t2.n)
    select * from t2 a where not exists(select 1 from t1 where t1.n>=a.n)

解决方案 »

  1.   

    not exists(select 1 from t1,t2 where t1.n>=t2.n) 只要t2有记录,这个条件是恒成立的
      

  2.   

    select 1 from t1,t2 where t1.n>=t2.n
    select 1 from t1 where t1.n>=a.n)这两个都不一样,结果为什么要一样?
      

  3.   

    说错,
    1.只要(select 1 from t1,t2 where t1.n>=t2.n)有记录条件就成立,返回t2的所有记录2.not exists(select 1 from t1 where t1.n>=a.n)
    是查询t2的n值小于t1的n的记录
      

  4.   

        是不是因为 t1.n>=t2.n  与 t1.n>=a.n是不一样的概念?t2表<>a表吗?
      

  5.   

    第一个括号里面的条件是独立的
    只要括号里面的条件满足那么就不会有数据出现
    就好比 if not exists(select 1 from t1,t2 where t1.n>=t2.n) 
    select * from t2 第二个用的是子查询条件,靠理解吧