如何在aws athena中附加两个具有不同列的表

how to append two tables with different columns in aws athena

我需要帮助编写一个查询,该查询将两个表附加一些相似的列和其他列。 例如,如果我有 2 个表,

Table 1:

   name    age    place
    n1      a1       p1
    n2      a2       p2
    n3      a3       p3

Table 2:

   name    place   country
    n4       p4      c4
    n5       p5      c5
    n6       p6      c6

我想追加这两个表以获得

Table 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

这可能吗? 谢谢

您可以使用带有占位符的 UNION 查询来查找每个 table:

上缺失的列
SELECT name, age, place, null AS country FROM table1
UNION ALL
SELECT name, null AS age, place, country FROM table2
ORDER BY name;

请注意,我创建了两列,以便每个结果集都具有相同的列集。