SQL UNION

The UNION operator is used to combine the result sets of two or more SELECT statements. It removes duplicate rows between the various SELECT statements.

Syntax

The basic syntax for UNION is:


SELECT column1, column2, ...
FROM table1
UNION
SELECT column1, column2, ...
FROM table2;

        

Example

Consider two tables Employees1 and Employees2 with similar structures. To get a combined list of employees from both tables:


SELECT EmployeeID, Name
FROM Employees1
UNION
SELECT EmployeeID, Name
FROM Employees2;