Oracle Union | union - oracle tutorial - sql tutorial

Learn oracle - oracle tutorial - Oracle union - oracle examples - oracle programs
What is Oracle UNION ?
- The Oracle UNION operator is used to combine the result sets of 2 or more Oracle SELECT statements.
- It removes duplicate rows between the various SELECT statements.

Syntax:
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions]
UNION
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions];
click below button to copy the code. By - oracle tutorial - team
- Note : Each SELECT statement within the UNION operator must have the same number of fields in the result sets with similar data types.

Oracle Union Query
Sample Database:
- We have a table called wikitechy_employee with four fields (id, name, position, and city). It contains the following data:

- We have another table called orders with three fields (id, customer_name, and orderid).

oracle tutorial , sql tutorial , sql , pl sql tutorial , oracle , pl sql , plsql
Example:
SELECT City FROM wikitechy_employee
UNION
SELECT City FROM orders
ORDER BY City;
click below button to copy the code. By - oracle tutorial - team
Note:
- There must be same number of expressions in both SELECT statements.
Union:

- Select statement is used to select city column from the wikitechy_employee table and similarly city column from orders table.
- Union Keyword is used to combines distinct values in city column from both tables.
- If several employee and customers share same city, each city will only be selected.
- Note: Use Union All keyword instead of union to select all the duplicate values.
Union UnionAll Except Intersect
