0% found this document useful (0 votes)
5 views

Union_Examples

Uploaded by

sai Charan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Union_Examples

Uploaded by

sai Charan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Combines the results of two or more SELECT queries and removes duplicates.

UNION The result set will contain distinct rows that appear in either of the result sets.

Similar to UNION, but it does not remove duplicates.


UNION ALL Returns all rows, including duplicates, that appear in either of the result sets.

Returns only the rows that are common to both SELECT queries.
INTERSECT Duplicates are automatically removed.
Returns rows from the first SELECT query that are not present in the second SELECT
query.
MINUS Duplicates are removed.

All queries combined by these set operators must have the same number of columns
and compatible data types in the corresponding columns.
Note
The column names in the result set are taken from the first SELECT statement in all
set operations
SELECT emp_name FROM employees
SELECT column_list FROM table1 UNION UNION
SELECT column_list FROM table2; SELECT dept_name FROM departments;
SELECT column_list FROM table1 SELECT emp_name FROM employees
UNION ALL UNION ALL
SELECT column_list FROM table2; SELECT dept_name FROM departments;
SELECT column_list FROM table1 SELECT emp_name FROM employees
INTERSECT INTERSECT
SELECT column_list FROM table2; SELECT dept_name FROM departments;
SELECT column_list FROM table1 SELECT emp_name FROM employees
MINUS MINUS
SELECT column_list FROM table2; SELECT dept_name FROM departments;
Combines result sets and removes duplicates.

Combines result sets but keeps duplicates.

Returns only the common rows between two result


sets.

Returns rows from the first query that are not in the
second query.

You might also like