结合2个不同但非常相似的表格

Mit*_*tch 0 sql t-sql sql-server union

我有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
Run Code Online (Sandbox Code Playgroud)

Raj*_*ore 5

做一个UNION,但首先你必须使表格结构相同.

在SELECT for Table1中,将Employment添加为NULL值列

在SELECT for Table2中,将Language添加为NULL值列

SELECT ActivityCategory, ActivityType, Nationality, Language, NULL AS Employment
FROM Table1
UNION
SELECT ActivityCategory, ActivityType, Nationality, NULL AS Language, Employment
FROM Table1
Run Code Online (Sandbox Code Playgroud)