假设两个表A B
a2和b2列的值有相同的部分也有不同的部分,如以下
a1 a2 
a   10
a   20
b   30
b  40
B 表中数据如下
b1 b2 。。
a  10
a  20
a  30
b  50A B两表有好多列,只有两列的数据可能相同,a1和b1肯定都是相同的,但对应的a2和b2不一定相同,也就是说a1+a2 与b1+b2 来比较时两表有差异的数据都要同时显示出来,跪求写法。

解决方案 »

  1.   

    select rtrim(a1)+rtrim(a2) from A
    except
    select rtrim(b1)+rtrim(b2) from B
      

  2.   

    我要显示A B 两表中其他的列哦,加入A表中还有a3,a4,B表中还有b3,b4,a3,a4和b3,b4都毫无关联,如果也要同步显示的话该如何更改sql语句呢
      

  3.   

    A表和B表的表结构是否一致?如果一致可以这样select a.* from a where not exists(select 1 from b where a.a1=b.b1 and a.a2=b.b2)
    union all
    select b.* from b where not exists(select 1 from a where b.b1=a.a1 and b.b2=a.a2)
    两表结构不一样的需要做类型转换
      

  4.   

    A,B两表除了a1对应b1,a2对应b2外,其他的字段都不一样,表结构也不一样。就是这样子所以很不好写,还请赐教。