还是先
select name,no
into #c
from table
where name='hello'再
select #c.name,b.number
from #c,table2 as b
where #c.no=b.no这样效率会更高吗? 这样写可以吗?

解决方案 »

  1.   

    效率是一样的。
    会自动优化,如果table1.no,table2.no都有索引,先连接后筛选。
    如果table1.no,table2.no没有索引,table1.name有索引,先筛选后连接。
    其它情况很难说,但是会自动优化。
      

  2.   

    SQL 6.5 以前和顺序有关,SQL 7 开始和顺序无关了,SQL Server 的优化器会自动调整 Where 子句中语句的顺序,以达到一个最优的效果。
      

  3.   


    select a.name,b.number 
    from table as a ,table2 as b
    where a.name='hello' and a.no=b.no