表A
num  adr
11  aa
22  bb
33  cc表B
id  acc
A   11
B   44
C   55
D   22
E   33找出B表中acc列不在表A中num列中的数据?即结果要得到为:     B 44
                                                         C 55

解决方案 »

  1.   

    select b.id,b.acc from tableb b LEFT JOIN tablea a on a.num=b.acc where a.num is null
      

  2.   

    select b.acc_nbr from yxyf_201107_country_nbr b LEFT JOIN old_country_num a on a.num=b.acc_nbr where a.num is null;
    我的是ORACLE数据库
      

  3.   

    select * from tableb b where not exists (select 1 from tablea a where a.num=b.acc);
      

  4.   

    not exists 也试过了,就是没结果
      

  5.   

    select b.id,b.acc from tableb b LEFT JOIN tablea a on a.num=b.acc where a.num is null;select * from tableb b where not exists (select 1 from tablea a where a.num=b.acc);select * from tableb b where b.acc not in (select a.num from tablea a);左连接,not exists,not in全在这里。如果都不行,就不是sql的问题了。