Oracle Tutorial

What is Oracle
SQL Keywords

Oracle Wildcards

Oracle Wildcards

Oracle Aliases

Oracle Aliases

MySQL Tutorial

MySQL Tutorial

PL/SQL Tutorial

PL/SQL Tutorial

Oracle Interview Questions

Oracle Interview Questions and Answers


Oracle UNION Operator

The Oracle UNION operator is allow you to combine the result-set of two or more SELECT statements together. It combines the both SELECT statement and removes duplicate rows between them. If SELECT statement have the same number of columns with similar data types and it should be in the same order.

Oracle UNION OPERATOR Syntax

To combine the result-set of two or more SELECT statements together, use the following syntax:

Syntax

SELECT col1,col2... FROM tablename1
UNION
SELECT col1,col2... FROM tablename2;

Parameters:

tablename: The table name from which you want to perform UNION operator.

UNION: To combine the result-set of two or more SELECT statements.

Oracle UNION OPERATOR example

The following Oracle, returns all the different "firstName", "lastName" and "address" from "tblCustomer" and "tblCustomerLoan" table:

Example

SELECT firstName, lastName, address FROM tblCustomer 
UNION
SELECT firstName, lastName, address FROM tblCustomerLoan;

Note:

In the above example, the UNION operator will return all distinict records from "tblCustomer" and "tblCustomerLoan" table.

You can use Oracle Command Line Client to use UNION operator to combine the result-set of two or more SELECT statements together. It will look like this: