[英]how to append two tables with different columns in aws athena
I want help in writing a query which appends two tables with some similar columns and other columns too.我需要帮助编写一个查询,该查询将两个表附加到一些类似的列和其他列。 For example if I have 2 tables,
例如,如果我有 2 张桌子,
Table 1:表格1:
name age place
n1 a1 p1
n2 a2 p2
n3 a3 p3
Table 2:表 2:
name place country
n4 p4 c4
n5 p5 c5
n6 p6 c6
I want to append these two tables to get我想附加这两个表以获得
Table 3:表3:
name age place country
n1 a1 p1 NULL
n2 a2 p2 NULL
n3 a3 p3 NULL
n4 NULL p4 c4
n5 NULL p5 c5
n6 NULL p6 c6
Is this possible?这可能吗? Thanks
谢谢
You can use a UNION query with placeholders for missing columns on each table:您可以使用带有占位符的UNION查询来查找每个表中缺失的列:
SELECT name, age, place, null AS country FROM table1
UNION ALL
SELECT name, null AS age, place, country FROM table2
ORDER BY name;
Notice that I have created two columns so that each result set has the same set of columns.请注意,我创建了两列,以便每个结果集都具有相同的列集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.