表A 
ID XM txf
1 A 10 
2 B 11 
表B 
ID XM lx 
3 C 12 
4 D 13 
我要这样的 
表B 
ID XM tx lx 
1 A 10 null 
2 B 11 null 
3 C null 12 
4 D null 13

解决方案 »

  1.   


    select id ,XM,txf as tx,null as lx
    from a
    union 
    select id ,XM,null as tx, lx as lx
    from b
      

  2.   

    select ID,XM,tx,NULL as lx
    from 表A
    union all 
    select ID,XM,NULL,lx
    from 表B
      

  3.   

    create table A (ID int, XM varchar(100), tx int)
    insert into A
    select 1, 'A', 10 union all
    select 2, 'B', 11 create table B(ID int, XM varchar(100), lx int)
    insert into B
    select 3, 'C', 12  union all
    select 4, 'D', 13 
    select id,xm,tx,null as lx
    from A
    union all
    select id,xm,null as tx,lx
    from Bdrop table A,B/*ID XM tx lx 
    1 A 10 null 
    2 B 11 null 
    3 C null 12 
    4 D null 13
    */
      

  4.   

    select id,xm,tx,null as lx
    from A
    union all
    select id,xm,null as tx,lx
    from B
      

  5.   

    create table a (ID int , XM nvarchar(10), txf int )
    insert into a select 1, 'A', 10 
    union select 2, 'B', 11 create table B (ID int , XM  nvarchar (10),lx  int)
    insert into b select 3 ,'C', 12 
    insert into b select 4, 'D', 13 
    select id ,XM,txf as tx,null as lx
    from a
    union 
    select id ,XM,null as tx, lx as lx
    from bid          XM         tx          lx          
    ----------- ---------- ----------- ----------- 
    1           A          10          NULL
    2           B          11          NULL
    3           C          NULL        12
    4           D          NULL        13(4 row(s) affected)