组合 2 个不同但相当相似的表
我有两个相似但不相同的表,因此不可能联合。我需要合并这些表,记住大约有 40 列,其中只有 20 列是两者共有的。关于最佳方法有什么想法吗?
Table1
ActivityCategory ActivityType Nationality Language
---------------------------------------------------------
Communication Telephone French French
Meeting Session British English
Table2
ActivityCategory ActivityType Nationality Employment
-----------------------------------------------------------
Communication Fax American Employed
Combined Table
ActivityCategory ActivityType Nationality Language Employment
----------------------------------------------------------------------
Communication Telephone French French
Meeting Session British English
Communication Fax American Employed
I have 2 tables that are similar but not the same so a union is not a possibility. I need to combine the tables bearing in mind there's about 40 columns where only 20 are common to both. Any ideas on the best approach?
Table1
ActivityCategory ActivityType Nationality Language
---------------------------------------------------------
Communication Telephone French French
Meeting Session British English
Table2
ActivityCategory ActivityType Nationality Employment
-----------------------------------------------------------
Communication Fax American Employed
Combined Table
ActivityCategory ActivityType Nationality Language Employment
----------------------------------------------------------------------
Communication Telephone French French
Meeting Session British English
Communication Fax American Employed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
进行 UNION,但首先必须使表的结构相同。
在 Table1 的 SELECT 中,添加“Employment”作为 NULL 值列
在 Table2 的 SELECT 中,添加“Language”作为 NULL 值列
Do a UNION but first you have to make the tables same in structure.
In the SELECT for Table1, add Employment as a NULL value column
In the SELECT for Table2, add Language as a NULL value column
联合什么可以联合,然后加入其余的列?
如果您只需要执行一次,则很有可能。我想即使有一个观点也是可能做到的。
Union what is possible to union, and later on join the rest of the collumns?
Pretty possible if you will need to do it only one time. I guess that even with a view its possible to do it.
Raj 的建议很好,但您可能想要执行 UNION ALL 而不是 UNION。
来自 BOL,
使用 UNION 需要付出一定的代价来保证没有重复项,但就您而言,听起来无论如何您都不会出现重复项。
Raj's suggestion is good, but you will probably want to do a UNION ALL and not a UNION.
From BOL,
Using UNION pays the price to guarantee no duplicates, but in your case, it sounds like you won't have duplicates anyway.