先执行结果集,在执行查询的 即是先select Aid from B在select * from A where id in()
子查詢原理是每查询一行就会执行一次子查询但你這個不是子查詢吧? 你這個是先 select Aid from B 獲取 ID 條件範圍 然後再查詢 A 表select *,(select Aid from B where id=t1.id) as cols1 from A as t1 這樣才是子查詢吧?
理解上是先处理select Aid from B 然后是select * from A where id in()但是,实际如何去做的,还是得看执行计划哦!
如果子段Mumber只有0,1,2三种情况 select * from A where Mumber>0 and id in(select Aid from B where Mumber=A.Mumber) 和 select * from A where Mumber=1 and id in(select Aid from B where Mumber=1) select * from A where Mumber=2 and id in(select Aid from B where Mumber=2) 的查询结果是否一样呢? 最后具体分析一下!谢谢!
即是先select Aid from B在select * from A where id in()
你這個是先
select Aid from B 獲取 ID 條件範圍
然後再查詢 A 表select *,(select Aid from B where id=t1.id) as cols1
from A as t1 這樣才是子查詢吧?
理解上是先处理select Aid from B 然后是select * from A where id in()但是,实际如何去做的,还是得看执行计划哦!
select * from A where Mumber>0 and id in(select Aid from B where Mumber=A.Mumber)
和
select * from A where Mumber=1 and id in(select Aid from B where Mumber=1)
select * from A where Mumber=2 and id in(select Aid from B where Mumber=2)
的查询结果是否一样呢?
最后具体分析一下!谢谢!
你使用SQL2005的估計執行計劃
就因該能看出不同