To combine the result of two
SELECT statements, use
- The number and the order of the columns in the select list of both queries must be the same.
- The data types must be compatible.
- Duplicate rows will be dropped.
SELECT select_list_1 FROM table_expresssion_1 UNION SELECT select_list_2 FROM table_expression_2
select 1 as n union select 2 as n;
n --- 1 2
select 1 as n union select 'a' as n;
ERROR: 22P02: invalid input syntax for integer: "a" LINE 1: select 1 as n union select 'a' as n; ^