The UNION operator is used to
combine the result-set of two or more SELECT statements.
Notice that each SELECT statement
within the UNION must have the same number of columns. The columns must also
have similar data types. Also, the columns in each SELECT statement must be in
the same order.
SQL UNION Syntax
SELECTcolumn_name(s)FROMtable1 UNION SELECTcolumn_name(s)FROMtable2;
Note:The UNION
operator selects only distinct values by default.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
The UNION operator is used to combine the result-set of two or more SELECT statements.
Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.
SQL UNION Syntax
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
Note: The UNION operator selects only distinct values by default.
SQL UNION ALL Syntax
SELECT column_name(s) FROM table1
UNION ALL
SELECT column_name(s) FROM table2;
Note : The UNION operator selects All (duplicate values also) values by default.
For Exp:
Union
Result :
Union All