有2个表A和B,
A表有字段a1,B表有字段b1,
a1有一下数据
2
3
4
5
7
8
...b1有一下数据
2
3
5
8
9
...
如何通过比对后找出A表字段a1在B表字段b1没有的项?
比如上面找出的就是:4,7,....
请大家帮忙,谢谢
由于分数不多 只有39了 不好意思 分不多

解决方案 »

  1.   

    select a1 from a
    minus 
    select b1 from b
      

  2.   


    SELECT * FROM a WHERE NOT EXISTS (SELECT 1 FROM b WHERE a.a1=b1);
      

  3.   

    select a.* from a where a1 not in(select b1 from b)select a.* from a where not exists(select 1 from b where b.b1 = a.a1)
      

  4.   

    SQL> ed
    已写入 file afiedt.buf  1  with a as(
      2  select 2 a1 from dual
      3  union all
      4  select 3 from dual
      5  union all
      6  select 4 from dual
      7  union all
      8  select 5 from dual
      9  union all
     10  select 7 from dual
     11  union all
     12  select 8 from dual),
     13  b as(
     14  select 2 b1 from dual
     15  union all
     16  select 3 from dual
     17  union all
     18  select 5 from dual
     19  union all
     20  select 8 from dual
     21  union all
     22  select 9 from dual)
     23  select a1 from a where not exists
     24* (select 1 from b where a.a1=b.b1)
    SQL> /        A1
    ----------
             7
             4
      

  5.   


    minus 差集select a1 from A minus select b1 from B