Using The Set Operators
Using The Set Operators
SET OPERATORS
UNION Operator
The UNION operator returns results from both queries after eliminating
duplications.
Using the UNION Operator
Display the current and previous job details of all employees. Display each
employee only once.
SELECT employee_id, job_id
FROM employees
UNION
SELECT employee_id, job_id
FROM job_history;
INTERSECT Operator
The INTERSECT operator returns rows that are common to both queries.
Display the employee IDs of those employees who have not changed their jobs
even once.
SET OPERATOR GUIDELINES
•The expressions in the SELECT lists must match in number and data type.
•Parentheses can be used to alter the sequence of execution.
•The ORDERBY clause:
–Can appear only at the very end of the statement
–Will accept the column name, aliases from the first SELECT statement, or the
positional notation.
The Oracle Server and Set Operators
•Duplicate rows are automatically eliminated except in UNIONALL.
•Column names from the first query appear in the result.
•The output is sorted in ascending order by default except in UNIONALL.