T-SQL 合并两个具有常见列和不常见列的表
问题描述:
这是我的问题.我有两个带有常见和不常见列的表,如下所示:在 T SQL 或 SSIS 中是否有一种有效的方法可以做到这一点?谢谢
Here is my problem. I have two tables with common and uncommon columns as follows: Is there an effective way of doing this in T SQL or SSIS? Thank you
表 1:
a b c
1 2 3
7 8 9
表 2:
a d k
4 6 7
9 0 2
合并表:
a b c d k
1 2 3 null null
7 8 9 null null
4 null null 6 7
9 null null 0 2
答
您可以使用 union 为缺少的列添加 null
You could use union adding null for missing column
select a,b,c, null d, null k
from table1
union
select a,null, null,d, k
from table1