select * from aa a,bb b where a.a=b.a and b.a like '%...%'
和select * from aa a where a.a exists (select a from bb b where a like '%...%' and a.a=b.a)
哪一句更有效率。 

解决方案 »

  1.   

    第2句有语法问题吧?where exists就够了。
    具体效率没测试过。
      

  2.   

    第一句中where条件的a.a=b.a需要判断所有两个表中的数据,如果表数据量大的话,效率会低
      

  3.   

    1,看2条sql语句的执行计划,这个比较有说服力啊!2,一般exists比无序表关联(tb1,tb2 where....)效率要高,所以第2句sql的效率一般比第一句的效率要高些。3,楼主的第2条sql语句语法有误,应该是 where exists吧!
      

  4.   

    当然是第二句效率高了,不过同LS的用WHERE EXISTS就行了
      

  5.   

    追加一个问题如果我还想在结果里显示bb里的一个内容如b.name可不可一这样写select a.*,b.name from aa a where  exists (select a,name from bb b where a like '%...%' and a.a=b.a) 
      

  6.   

    这个貌似不行吧,from子句里没有b这个表,不能选择出来
      

  7.   

    可以这样写
    select a.*,b.name from aa a,bb b where  exists (select * from bb b where a like '%...%' and a.a=b.a) 
      

  8.   

    第二句好些_______________________________
    DBA请进群QQ群:88039805
      

  9.   

    like '%...%' 不会用到索引的,like '...%' 就会用到索引
      

  10.   

    这两个语句的效率高低比较已经不再重要,重要的是这两个语句的效率都很低下,数据量稍大时,都会让很有耐心的人变得没有耐心:)最好不要用like '%...%' ,即使要用like,也要这样like '...%',为什么不用全文索引呢?比用like的速度快至少100倍以上。请参考:Oracle中文全文索引
      

  11.   

    select * from aa a where a.a exists (select a from bb b where a like '%...%' and a.a=b.a) ;这个语法正确??子查询效率稍微高点!
      

  12.   

    应该这样写
    select * from aa a where exists (select a from bb b where a like '%...%' and a.a=b.a)