Oracle Class - SET Operators
Oracle Class - SET Operators
+91 – 7841038548
SQL CLASS –
SET Operator –
The SET operators combine the results of two or more queries into one
result. Queries containing SET operators are called compound queries.
The number of columns and the data types of the columns being
selected must be identical in all the SELECT statements used in the
query. The names of the columns need not be identical.
All SET operators have equal precedence. If a SQL statement contains
multiple SET operators, the Oracle server evaluates them from left (top)
to right (bottom) if no parentheses explicitly specify another order.
Different Types of SET operators are –
1. UNION Operator
2. UNION ALL Operator
3. INTERSECT Operator
4. MINUS Operator
Operator Returns
UNION Combine two or more result sets into a single set, without duplicates.
UNION ALL Combine two or more result sets into a single set, including all duplicates.
INTERSECT Takes the data from both result sets which are in common.
Takes the data from first result set, but not the second (i.e. no matching to
MINUS
each other)
2ND FLOOR, KRUSHNA PARK, ABOVE MASA MASA RESTAURANT, KHARADI, PUNE, 411014
1
Website - https://minskole.in/ Email - [email protected]
+91 - 7841938548
+91 – 7841038548
Example of Joins –
2ND FLOOR, KRUSHNA PARK, ABOVE MASA MASA RESTAURANT, KHARADI, PUNE, 411014
2
Website - https://minskole.in/ Email - [email protected]
+91 - 7841938548
+91 – 7841038548
Note – Whenever set operators are used select statement must have
Equal no of columns.
Similar data type columns.
UNION –
2ND FLOOR, KRUSHNA PARK, ABOVE MASA MASA RESTAURANT, KHARADI, PUNE, 411014
3
Website - https://minskole.in/ Email - [email protected]
+91 - 7841938548
+91 – 7841038548
The UNION operator returns all rows selected by either query. Use the
UNION operator to return all rows from multiple tables and eliminate
any duplicate rows.
Guidelines –
Example –
2ND FLOOR, KRUSHNA PARK, ABOVE MASA MASA RESTAURANT, KHARADI, PUNE, 411014
4
Website - https://minskole.in/ Email - [email protected]
+91 - 7841938548
+91 – 7841038548
2ND FLOOR, KRUSHNA PARK, ABOVE MASA MASA RESTAURANT, KHARADI, PUNE, 411014
5
Website - https://minskole.in/ Email - [email protected]
+91 - 7841938548
+91 – 7841038548
UNION ALL –
2ND FLOOR, KRUSHNA PARK, ABOVE MASA MASA RESTAURANT, KHARADI, PUNE, 411014
6
Website - https://minskole.in/ Email - [email protected]
+91 - 7841938548
+91 – 7841038548
Combines the results of two SELECT statement into one result set
including the duplicates.
Guidelines –
Unlike UNION, duplicate rows are not eliminated and the output is not
sorted by default.
Example –
2ND FLOOR, KRUSHNA PARK, ABOVE MASA MASA RESTAURANT, KHARADI, PUNE, 411014
7
Website - https://minskole.in/ Email - [email protected]
+91 - 7841938548
+91 – 7841038548
UNION ALL
Select Empid, loc From Employee2 ORDER BY Empid;
INTERSECT –
Use the INTERSECT operator to return all rows common to multiple queries.
2ND FLOOR, KRUSHNA PARK, ABOVE MASA MASA RESTAURANT, KHARADI, PUNE, 411014
8
Website - https://minskole.in/ Email - [email protected]
+91 - 7841938548
+91 – 7841038548
Guidelines –
Reversing the order of the intersected tables does not alter the result.
Intersect does not ignore NULL values.
Example –
MINUS –
The MINUS operator returns rows from the first query that is not present in
the second query.
2ND FLOOR, KRUSHNA PARK, ABOVE MASA MASA RESTAURANT, KHARADI, PUNE, 411014
9
Website - https://minskole.in/ Email - [email protected]
+91 - 7841938548
+91 – 7841038548
Notes –
The Queries are all executed independently but their output is merged.
Only final query ends with a Semicolon.
Example –
__________________________THANK YOU____________________________
2ND FLOOR, KRUSHNA PARK, ABOVE MASA MASA RESTAURANT, KHARADI, PUNE, 411014
10
Website - https://minskole.in/ Email - [email protected]