请问各位高手,以下两条语句在相同的环境下查询出来为什么是完全不一样的结果?帮我理解下!谢了! 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)
select * from t2 a where not exists(select 1 from t1 where t1.n>=a.n)
select 1 from t1 where t1.n>=a.n)这两个都不一样,结果为什么要一样?
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的记录
只要括号里面的条件满足那么就不会有数据出现
就好比 if not exists(select 1 from t1,t2 where t1.n>=t2.n)
select * from t2 第二个用的是子查询条件,靠理解吧