谁能分析一下这条sql语句的查询过程
select * from A where id in(select Aid from B)
是不是每查询一行就会执行一次子查询;还是先把子查询保存一个结果,以后每次就调用这个结果!!!

解决方案 »

  1.   

    先执行结果集,在执行查询的
    即是先select Aid from B在select * from A where id in()
      

  2.   

    子查詢原理是每查询一行就会执行一次子查询但你這個不是子查詢吧?
    你這個是先
    select Aid from B 獲取 ID 條件範圍 
    然後再查詢 A 表select *,(select Aid from B where id=t1.id) as cols1 
    from A as t1 這樣才是子查詢吧?
      

  3.   


    理解上是先处理select Aid from B 然后是select * from A where id in()但是,实际如何去做的,还是得看执行计划哦!
      

  4.   

    如果子段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)
    的查询结果是否一样呢?
    最后具体分析一下!谢谢!
      

  5.   

    這個要根據你表結構分析了,,,
    你使用SQL2005的估計執行計劃
    就因該能看出不同