i have tow table,one is tableA and the other is tableB
tableA's strution is as fellow:
   TableA
A 1
B 2
  TableB
B 2
C 3
D 4
in the end ,the Result i want to get is :
TableC
A 1 null
B 2 2
C 3 null
D 4 null

解决方案 »

  1.   

    select table2.clo1,table2.clo12,table1.clo2
    from  table2 left join table1 on table1.clo1=table2.clo1
    union 
    select table1.clo1,table1.clo2,table2.clo12 
    from table1 left join table2 on table1.clo1=table2.clo1
      

  2.   

    還可加一個Order by 排序﹕
    select table2.clo1,table2.clo12,table1.clo2
    from  table2 left join table1 on table1.clo1=table2.clo1 
    union 
    select table1.clo1,table1.clo2,table2.clo12 
    from table1 left join table2 on table1.clo1=table2.clo1 
    order by table2.clo1,table2.clo12,table1.clo2