3 回答
TA贡献1821条经验 获得超6个赞
只需将空值放入缺失的列中并使用UNION ALL
select name, surname, age, gender, height, null, null from table1
union all
select name, surname, age, gender, null, dateofbirth, origin from table2
正如@TheImpaler 所提到的,没有办法手动选择列。
TA贡献1847条经验 获得超11个赞
请试试这个。
SELECT
Name, Surname, Age, Gender, Height,NULL AS DateOfBirth,NULL AS Origin
FROM
table1
UNION ALL
SELECT
Name, Surname, Age, Gender, NULL AS Height, DateOfBirth, Origin
FROM
table2
TA贡献1839条经验 获得超15个赞
您可以使用 ROW_NUMBER 函数
SELECT t1.Column1, t1.Column2, t2.Column3, t2.Column4
FROM (
SELECT Column1, Column2,
ROW_NUMBER() OVER (ORDER BY Column1) AS rn
FROM Table1) AS t1
FULL OUTER JOIN (
SELECT Column3, Column4,
ROW_NUMBER() OVER (ORDER BY Column3) AS rn
FROM Table2) AS t2
ON t1.rn = t2.rn
- 3 回答
- 0 关注
- 83 浏览
添加回答
举报