Set Operations (1)
Set Operations (1)
The SQL Set operation is used to combine the two or more SQL SELECT
statements.
1. Union
2. UnionAll
3. Intersect
4. Minus
1. Union
o The SQL Union operation is used to combine the result of two or more SQL
SELECT queries.
o In the union operation, all the number of datatype and columns must be
same in both the tables on which UNION operation is being applied.
o The union operation eliminates the duplicate rows from its resultset.
Syntax
Example:
ID NAME
1 Jack
2 Harry
3 Jackson
The First table
ID NAME
3 Jackson
4 Stephan
5 David
The Second table
ID NAME
1 Jack
2 Harry
3 Jackson
4 Stephan
5 David
2. Union All
Union All operation is equal to the Union operation. It returns the set without
removing duplication and sorting the data.
Syntax:
ID NAME
1 Jack
2 Harry
3 Jackson
3 Jackson
4 Stephan
5 David
The result set table will look like:
3. Intersect
Syntax
Example:
ID NAME
3 Jackson
4. Minus
Syntax:
Example
ID NAME
1 Jack
2 Harry