SQL Union
The SQL UNION is a set operator that combines the results of two or more SELECT statements into a single result set. The union operator eliminates duplicate rows between the various SELECT statements.
Here’s the syntax for the UNION operator:
SELECT column1, column2, ...
FROM table1
UNION
SELECT column1, column2, …
FROM table2;
The columns in each SELECT statement must match terms of number and data type. Plus, the column names in the final result set follow the names in the first SELECT statement.
It is important to note that the SQL UNION operator selects only distinct values by default. To include duplicates, you can use the UNION ALL operator instead.
SELECT column1, column2, …
FROM table1
UNION ALL
SELECT column1, column2, …
FROM table2;