请问一个如何对多表进行完整外部联接的问题
有三个表A,B,C有一个共同的字段
A:                  B:                        C:
字段A1 字段xh           字段B1  字段xh             字段C1   字段xh
 a1        1               b1      2                 c1         3
 a2        2               b2      3                 c2         4
 a3        3               b3      4                 c3         5
希望得到如下表:
字段xh  字段A1  字段B1  字段C1
  1       a1
  2       a2      b1
  3       a3      b2       c1
  4               b3       c2
  5                        c3
不太懂完整外连接的用法,只知道左,右连接使用*=和=*
那外连接呢?谢谢

解决方案 »

  1.   

    select xh,A1,B1,C1 from A full join B on A.xh=B.xh full join C on A.xh=C.xh
      

  2.   

    楼上select A.xh,A1,B1,C1 from A full join B on A.xh=B.xh full join C on A.xh=C.xh
    能得到如下:
    字段xh  字段A1  字段B1  字段C1
      1       a1
      2       a2      b1
      3       a3      b2       c1
                      b3       c2
                               c3
    但是我想得到把字段xh所有值显示出来
    怎么办? 
    如下:
    字段xh  字段A1  字段B1  字段C1
      1       a1
      2       a2      b1
      3       a3      b2       c1
      4               b3       c2
      5                        c3
      

  3.   

    这样试试:
    declare @ta table(A1 varchar(10),xh int)
    declare @tb table(B1 varchar(10),xh int)
    declare @tc table(C1 varchar(10),xh int)
    insert @ta
    select 'a1',1 union all
    select 'a2',2 union all
    select 'a3',3 
    insert @tb
    select 'b1',2 union all
    select 'b2',3 union all
    select 'b3',4 
    insert @tc
    select 'c1',3 union all
    select 'c2',4 union all
    select 'c3',5 select 
    isnull(a.xh,isnull(b.xh,c.xh)),
    isnull(a.A1,''),
    isnull(b.B1,''),
    isnull(c.C1,'')
    from @ta a 
    full join @tb b on a.xh = b.xh
    full join @tc c on b.xh = c.xh
    order by 1
      

  4.   

    不好意思
    没看仔细
    hellowork(一两清风)  正确