Hellow i have two tables in Vertica SQL:
table 1
col1 col2 col3
1 3 5
2 4 6
table 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:
col1 col2 col3
1 3 5
2 4 6
11 33 NULL
22 44 NULL
How can I do it in vertica
use null
as follows:
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:
select col1, col2, col3
from table1
union all
select col1, col2, NULL as col3
from table2;
UNION
incurs overhead for removing duplicates. In general, you should use UNION ALL
unless you intend to remove duplicates.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.