[英]Union tables in Vertica SQL where tables have different order of columns?
[英]Union all in Vertica SQL based on tables with different number of columns?
你好,我在 Vertica SQL 中有两个表:
表格1
col1 col2 col3
1 3 5
2 4 6
表 2
col1 col2
11 33
22 44
我想 UNION 这两个表,因此我想拥有:
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
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.