select a.xxx
 from a,b
where a.xxx=b.xxx and not in (select xxxx from b)
这样稍微能快些.不过还有更好的方法的.

解决方案 »

  1.   

    先试试这句
    select xxx from a where xxx in ( select xxx from c minus select xxx from b ) 
    不行的话可以使用如下如果c与b中xxx唯一性很高的话,在两表对xxx字段建B*索引
    如果重复性很高,建位图索引
      

  2.   

    select a.xxx from a,b,c where a.xxx=c.xxx and a.xxx<>b.xxx 
    在三张表的xxx列上建索引.
      

  3.   

    dinya2003(dinya 11i) :
    SQL有错误,这样会产生大量记录
      

  4.   

    同意 dinya2003(dinya 11i) 的作法.
      

  5.   

    dinya2003(dinya 11i) 方法不错
      

  6.   

    其实现在的not in早已经被优化过了,oracle,sybase都会将not in 看成exists字句,所以最好的办法可以在b , c 表对xxx建索引.dinya2003(dinya 11i)的方法是有问题的
    连接表的时候一般都不会用不等于方式,这样会选出几百万行数据,如果a有
    a有记录
    1

    3b有记录

    4
    5c有记录 
    3
    本来按楼主需要是没有一条记录,如果用diny2003的将会选出
    3
    3
    因为3<>4 3<>5
      

  7.   

    试试
    select xxx from a 
    where not exists(select 1 from b where a.xxx = b.xxx)
    and exists (select 1 from c where a.xxx = c.xxx)
      

  8.   

    dinya2003(dinya 11i) 的方法试过了,查出6千余万条记录,可怕
      

  9.   

    非常感谢各位相助,sjun66(无处不在) 的sql结果正确,用时15秒,终于搞定了