Union all in Vertica SQL 基于具有不同列数的表?

Union all in Vertica SQL based on tables with different number of columns?

你好,我在 Vertica 中有两个 tables SQL:

table 1

col1  col2  col3
1      3    5
2      4    6

table 2

col1  col2
11    33
22    44

我想将这两个 table 联合起来,因此我希望得到:

col1  col2  col3
1      3     5
2      4     6
11     33    NULL
22     44    NULL

如何在vertica中实现

使用null如下:

select col1, col2, col3 from table1
union 
select col1, col2, null from table2

一般来说,您应该使用 UNION ALL 并使用您想要的任何默认值定义额外的列:

select col1, col2, col3
from table1
union all
select col1, col2, NULL as col3
from table2;

UNION 会产生删除重复项的开销。一般来说,除非您打算删除重复项,否则您应该使用 UNION ALL