有两个表  表A,表B 两个表通过ID连接 已知道表A中有记录 3W条左右 ,表B有记录300W左右。
现语句如下:select ID from 表A a where ( NO > '苏B' or NO < '苏A' ) and State = 0 and not exists( select 1 from 表B b where a.ID = b.ID );但是这样查询很慢(经过测试主要是not exists 条件比较慢),请问是否有其他语句能够提高速度并符合上述查询条件?

解决方案 »

  1.   

    select ID from 表A a,表b b 
         where ( NO > '苏B' or NO < '苏A' ) and State = 0 and 
               a.id=b.id(+)
               and b.id is null
      

  2.   

     2楼的不错,ID如果不是主键可以为其建个索引,NO也建个索引试试。
      

  3.   


    A表左联接B表,取关联不上的数据.
    也就相当于取了在A表而不在B表的数据.
      

  4.   


    select ID from 表A a left join 表B b on a.ID = b.ID  and b.ID is null 
    where ( NO > '苏B' or NO < '苏A' ) and State = 0 10g对于
    我这也写 觉得更加规范些
      

  5.   

    有地方错了正确如下
    select ID from 表A a left join 表B b on a.ID = b.ID  where ( NO > '苏B' or NO < '苏A' ) and State = 0 and b.ID is null 
      

  6.   

    state =0   声明是什么意思 ??