select a1.xx,b.xx  from  (select   a.xx   from   a   where   a.id < 100)   a1   left   join   b   on   a1.id   =   b.id select   a.xx,b.xx   from   a   left   join   b   on   a.id   =   b.id   where   a.id   < 100select   a.xx,b.xx   from   a,b  where a.id(+) =  b.id   where   a.id(+)< 100
请问以上三个语句哪个效率高?请说明原因!

解决方案 »

  1.   

    select  a.xx,b.xx  from  a,b  where a.id(+) =  b.id  where  a.id(+) < 100 
    报错select a1.xx,b.xx  from  (select  a.xx  from  a  where  a.id < 100)  a1  left  join  b  on  a1.id  =  b.id select  a.xx,b.xx  from  a  left  join  b  on  a.id  =  b.id  where  a.id  < 100 
    一样
      

  2.   

    不好意思,今天喝多了,写错了.正确的写法: 
    select a1.xx,b.xx  from  (select  a.xx  from  a  where  a.id < 100000)  a1  left  join  b  on  a1.id  =  b.id select  a.xx,b.xx  from  a  left  join  b  on  a.id  =  b.id  where  a.id  < 100000select  a.xx,b.xx  from  a,b  where a.id =  b.id(+)  and a.id < 100000如果a表中的数据是十万条以上,请问上述三个语句哪个效率高?请说明原因! 
      

  3.   

    一样
    left join和用(+)是一样的
    你去测试下执行计划和时间看看就知道了
      

  4.   

    可是有人说(+)比left join 快.
      

  5.   

    效率先不说,在某些时候,执行结果是不一样的。
    参照
    http://hi.baidu.com/kokyu/blog/item/0ffc35cd8c4f74550fb345b6.html
    http://www.diybl.com/course/7_databases/oracle/oraclejs/2008108/149307.html
      

  6.   

    请问在Oracle里,先执行from 然后执行where 最后再执行left join , 对吗? 
      

  7.   

    关键是看ORACLE的执行计划,环境不同效率也不一样。
      

  8.   

    上述3种写法只是逻辑上的语义不同,对oracle优化器而言没有区别。