2>
select * from table1,table2 where table1.id=table2.id and substr(table2.code,1,3)='001'
比较快

解决方案 »

  1.   

    1>
    select * from table1,table2 where table1.id=table2.id and substr(table2.code,1,3)='001'效率高。
      

  2.   

    to wangybyangxr(王永斌) 
    你的意思是用表连接比较的快,对吗
      

  3.   

    用in关键字会造成全表扫描.
    第一条改为
    select * from table1,table2 where table1.id=table2.id and table2 like '001%'
    会好得多.
      

  4.   

    哦.错.少个字段.
    select * from table1,table2 where table1.id=table2.id and table2.code like '001%'
      

  5.   

    应该是
    select * from table1,table2 where table1.id=table2.id and substr(table2.code,1,3)='001'
    比较快吧。set timing on,打开记时,看看他的执行事件。
      

  6.   

    to hero1981(英雄) 
    对,我的意思是用表连接比较的快。
      

  7.   

    select * from table1,table2 where table1.id=table2.id
     and table2.code like '001%';
    比较快,
    条件左边尽量不要使用函数,会破坏索引.
      

  8.   

    使用substr会使索引失效.除非你建立基于函数的索引.
    因此like还是适合些.
      

  9.   

    肯定是1快,至于like还是substr自己看看哪个执行时间短就知道了,我们不清楚你的数据结构。
      

  10.   

    select * from table1,table2 where table1.id=table2.id and substr(table2.code,1,3)='001'
    快一些,而且你可以写成
    select * from table1,table2 where table1.id=table2.id and table2.code >='001' and table2.code <='001' + 'z'这样你在索引里包含table2.code会更快一些
      

  11.   

    1快
    TABLE2记录较少,你可以让它做基表即"from table1,table2 ",你现在是对的!如果是三张表以上一般以起中间联系作用的那张表作为基表. 所谓基表就是放在"FROM"最后的那张表.
      

  12.   

    哈哈 见识 谢谢老大们 select * from table1,table2 where table1.id=table2.id and table2.code >='001' and table2.code <='001' + 'z'其中的'z'这种是什么写法
      

  13.   

    用IN 的比较慢
    别的不说,碰到集合查询像IN, NOT IN, EXISTS ..,Oracle 本身会试图把集合查询转换成表连接,如果转换不成,则会照原样查询
    另外,IN也会造成全表扫描,table1中有8千条记录就要判断8千次
      

  14.   

    哈哈 见识 谢谢老大们 select * from table1,table2 where table1.id=table2.id and table2.code >='001' and table2.code <='001' + 'z'其中的'z'这种是什么写法你的这种写法是错误的,字符串不能象'001' + 'z'这样相加,这样还'001'||'z'差不多
      

  15.   

    1快很多,两条SQL对比应该是好几倍的处理时间差距