SQL UNION Operator (original) (raw)
Last Updated : 13 Apr, 2026
The SQL UNION operator is used to combine the result sets of two or more SELECT queries into a single output. It removes duplicate rows and returns only unique records from all combined queries.
- UNION ALL includes all rows, even duplicates.
- Queries must have matching columns and data types.
- Helpful for combining data from different sources.
**Example: First, we create a demo SQL database and tables, on which we will use the UNION Operator command.

Table1

Table2
**Query:
SELECT city FROM Table1
UNION
SELECT city FROM Table2;
**Output:

**Syntax:
SELECT column_name FROM table1
UNION
SELECT column_name FROM table2;
Examples of SQL UNION
Let's look at an example of UNION operator in SQL to understand it better. Let's create two tables "Emp1" and "Emp2";

Emp1 Table

Emp2 Table
Example: SQL UNION Operator
In this example, we find the countries (only unique values) from both the "Table1" and the "Table2" tables:
**Query:
SELECT Country FROM Emp1
UNION
SELECT Country FROM Emp2
ORDER BY Country;
**Output:

Output after applying Union operator
**Note: The
UNIONoperator combines the results of two queries and removes duplicate rows, whileUNION ALLincludes all rows from both queries without eliminating duplicates.