Set Operators
Set Operators
• allows you to combine two or more result sets of queries into a single
result set.
Syntax
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
Basic Rules
✓ First, the number and the orders of columns that appear in all
SELECT statements must be the same.
✓ Second, the data types of columns must be the same or convertib
UNION Operator- Example
First Second
ID Name ID Name
1 Abhi 2 Anu
2 Anu 3 Meena
Example
SELECT * from First
UNION ID Name
2 Anu
3 Meena
UNION ALL Operator
First Second
ID Name ID Name
1 Abhi 2 Anu
2 Anu 3 Meena
Example
SELECT * from First
UNION ALL ID Name
2 Anu
2 Anu
3 Meena
INTERSECT Operator
First Second
ID Name ID Name
1 Abhi 2 Anu
2 Anu 3 Meena
Example
SELECT * from First
INTERSECT ID Name
First Second
ID Name ID Name
1 Abhi 2 Anu
2 Anu 3 Meena
Example
SELECT * from First
MINUS ID Name