Union and Union All in SQL
Union: The Union operator in SQL is used to combine the results of two or more SELECT QUERIES
into a single result set and give the unique rows by removing duplicate rows
To use UNION, keep in mind:
- For all SELECT commands number of columns must be the same
- The data type for the corresponding position of columns will be the same
- columns should be listed in the same order across all SELECT statements
example:
SELECT ID FROM CUSTOMERS
UNION
SELECT ID FROM ORDERS;
UNION ALL: The Union All operator in SQL is used to combine the results of two or more SELECT QUERIES into a single result, and gives all rows by not removing duplicate rows
example:
SELECT id from customers
UNION ALL
SELECT id from orders
Comments
Post a Comment