简体   繁体   English

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

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

Hellow i have two tables in Vertica SQL:你好,我在 Vertica SQL 中有两个表:

table 1表格1

col1  col2  col3
1      3    5
2      4    6

table 2表 2

col1  col2
11    33
22    44

And I would like to UNION these two tables, so as as result I would like to have:我想 UNION 这两个表,因此我想拥有:

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

How can I do it in vertica我怎样才能在vertica中做到这一点

use null as follows:使用null如下:

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

In general, you should use UNION ALL and define the extra column with whatever default value you want:通常,您应该使用UNION ALL并使用您想要的任何默认值定义额外的列:

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

UNION incurs overhead for removing duplicates. UNION会产生删除重复项的开销。 In general, you should use UNION ALL unless you intend to remove duplicates.通常,除非您打算删除重复项,否则您应该使用UNION ALL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM