select c1 as y,c2,null as d2 from t1
union all
select d1,c2,d2 from t2

解决方案 »

  1.   

    libin_ftsafe(子陌红尘) 你代码写出来,应该解释一下嘛,人家也是学习来的
      

  2.   

    union all 是连接合并两个查询的结果,有 all 记录可以重复,没有 all 记录不会重复
      

  3.   

    declare @t1 table(c1 varchar(10),c2 varchar(10))
    declare @t2 table(d1 varchar(10),c2 varchar(10),d2 varchar(10),d3 varchar(10))insert @t1 
    select 'aa','aa1' union all
    select 'bb','bb1'insert @t2
    select 'dd','aa1','dd2','dd3' union all
    select 'ff','bb1','ff2','ff3' union all
    select 'gg','aa1','gg2','gg3' union all
    select 'hh','aa1','hh2','hh3'select c1 as y ,c2, null as d2 from @t1 union all
    select d1 as y ,c2,d2  from @t2----------------------------------
    aa aa1 NULL
    bb bb1 NULL
    dd aa1 dd2
    ff bb1 ff2
    gg aa1 gg2
    hh aa1 hh2