SET Operators:
Set operators are used to combine the results of two or more SELECT statements.
Types of SET Operators:
1. UNION Operators
2. UNION ALL Operators
3. INTERSECTION Operators
4. EXCEPT Operators
5. MINUS Operators
1. UNION Operators:
The UNIONoperator combines the results of two SELECT statements and returns
only distinct rows.
Syntax: SELECT column_list FROM table1 UNION SELECT column_list FROM table2;
Ex: SELECT * FROM ORACLE UNION SELECT * FROM UIUX;
2. UNION ALL Operators:
The UNION ALL operator combines the results of two SELECT statements and
returns all rows, including duplicates.
Syntax: SELECT column_list FROM table1 UNION ALL SELECT column_list FROM
table2;
Ex: SELECT * FROM ORACLE UNION ALL SELECT * FROM UIUX;
3. INTERSECTION Operators:
The INTERSECToperator returns only the rows that are common to both SELECT
statements.
Syntax: SELECT column_list FROM table1 INTERSECT SELECT column_list FROM
table2;
Ex: SELECT * FROM ORACLE INTERSECT SELECT * FROM UIUX;
4. EXCEPT Operators:
It eliminates the second table and common rows or part of both tables (Table1 and Table2)
and returns only the first table rows which are not a part of common rows.
Syntax: SELECT column_list FROM table1 EXCEPT SELECT column_list FROM
table2;
Ex: SELECT * FROM ORACLE EXCEPT SELECT * FROM UIUX;
5. MINUS Operators:
The MINUSoperator returns the rows from the first SELECT statement that are not
present in the second SELECT statement.
Syntax: SELECT column_list FROM table1 MINUS SELECT column_list FROM
table2;
Ex: SELECT * FROM ORACLE MINUS SELECT * FROM UIUX;
Performance Consideration:
1. Union requires sorting and removing duplicates, which can be slower.
2. Indexes: Proper indexing can improve the performance of set operations.
3. Analyze and optimize the execution plans for complex queries involving set operators.
Restrictions:
1. The set operators are not valid on columns of type BLOB, CLOB, BFILE, VARRAY,
or nested table.
2. The UNION, INTERSECT, EXCEPT, and MINUSoperators are not valid on LONG
column
s.
3. If the select list preceding the set operator contains an expression, then you
must provide a column alias for the expression in order to refer to it in the
order_by_clause.
4. You cannot specify the order_by_clausein the subquery of these operators.
5. You cannot also specify the for_update_clausewith the set operators.
Today’s Task:
1. DATATYPES:
SELECT emp_id FROM ORACLE UNION SELECT emp_name FROM UIUX;
2. NULL VALUES:
3. Set Operators with single table content?
7
8