SQL>select * from a,b where a.key not in (select b.key from b)

解决方案 »

  1.   

    Do not use NOT IN statements, because it's efficiency  is very very low. Try this:
     select a.* from a,b where a.keycol=b.keycol(+) and b.keycol is null
      

  2.   

    why???please tell me!!Thanks....
    what mean "b.keycol(+)"??????I have never saw it!!
      

  3.   

    a.keycol=b.keycol(+) means left join. 
     a.keycol(+)=b.keycol means right join.  if you are using oracle 9i now, you can use left(right) join in 
     your sql statements,because oracle 9i supports SQL99 standard. BTW: you may read some oracle sql/plsql ariticles and documentation 
          to learn more about it.
     
      

  4.   

    select * from a where not exists(select 1 from b where a.id=b.id)
      

  5.   

    .keycol=b.keycol(+) means left join. 
     a.keycol(+)=b.keycol means right join. 
    用这样的方法效率好点:
      

  6.   

    select a.* from a,b where a.keycol=b.keycol(+);
    这是外连接,意思就是扩展b表!!
      

  7.   

    可用使用 minus 关键字.
    如果两个表的结构是相同的话:
    select * from a minus select * from b;  <- (显示在 A 表里,B 表没有的记录)也可以指定字段:
    select field1,field2 from a minus select field3,field4 from b注意: 只有字段类型相同才可以进行比较.
      

  8.   

    select * from a where not exists(select 1 from b where a.id=b.id)
    这里的1代表什么啊
      

  9.   

    agree on leecooper0918(爱一个人好难) .
      

  10.   


     人家问的是比较记录 搞什么字段相同来比较
     ---------------------------------------
      faint, 搞不懂你在说什么? 
     请看清楚楼主的问题再发言  如何从表A里抽取表B里没有的纪录 有共同的key字段 
      ----------------------------------------------