两表结构如下:
A表
字段一  字段二
123  1
123  2
123  3
444  8
444  8
247  6
852  5B表
字段一  字段二
123  1
123  3
444  8
852  5请问通过什么SQL可以知道B表对于A表来说缺少了
123  2
444  8
247  6
852  5
内容。

解决方案 »

  1.   

    select col1,col2 from a where not exists (select col1,col2 from b where a.col1=b.col1 and a.col2=b.col2);
      

  2.   

    select col1,col2 from a where not exists (select col1,col2 from b where a.col1=b.col1 and a.col2=b.col2);
      

  3.   

    这个题,另一小版也有。
    A表中有两条444 8,B表中有一条444 8。
    要求两表之差也有444 8。
    用上述语句或MINUS都不能满足要求。
    我已用分析函数解决了。具体思路为:为每条记录
    加一个rownum,一般都为1,但是对于记录重复的
    就会为2,这样就把两条相同记录区分开来了。‘
    再进行MINUS,就没问题。
      

  4.   

    select col1,col2 from a where col2 not in (select col1,col2 from b where a.col1=b.col1 and a.col2=b.col2);
      

  5.   

    这样写可以:
    select test_id,test_name from test_a a where (nvl(a.test_id,'')||nvl(a.test_name,'')) not in 
    (select nvl(b.test_id,'')||nvl(b.test_name,'') from test_b b) order by a.test_id ;