Why Learn It?
  Using Union clause
Previous previous|next Next Page

Used to combine the results of two component queries into a single result.

Queries containing set operators are called compound queries

The corresponding expressions in the select lists of the component queries of a compound query must match in number and datatype. If component queries select character data, the datatype of the return values are determined as follows:

  • If both queries select values of datatype CHAR, the returned values have datatype CHAR.
  • If either or both of the queries select values of datatype VARCHAR2, the returned values have datatype VARCHAR2

Example

  
SELECT FIRST_NAME, LAST_NAME, JOB_ID, SALARY, HIRE_DATE START_DATE 
FROM EMPLOYEES WHERE EMPLOYEE_ID =
(select EMPLOYEE_ID from EMPLOYEES where LAST_NAME = 'De Haan')
UNION
SELECT '','', JOB_ID, SALARY, START_DATE START_DATE 
FROM JOB_HISTORY WHERE EMPLOYEE_ID =
(select EMPLOYEE_ID from EMPLOYEES where LAST_NAME = 'De Haan')
ORDER BY START_DATE