UNION

SQL UNION Keyword

The UNION command combines the result sets of two or more SELECT statements into a single result set, returning only distinct values. The columns in each SELECT must have the same number of columns, in the same order, and with compatible data types.

Tutorials dojo strip

SQL UNION Syntax

SELECT column1, column2, ...
FROM table1
UNION
SELECT column1, column2, ...
FROM table2
ORDER BY column_name;

SQL UNION Example

This query combines distinct gender values from Patients and distinct specialty values from Doctors as a single list.

SELECT gender AS info
FROM Patients
UNION
SELECT specialty
FROM Doctors
ORDER BY info;

SQL UNION Labs

Tutorials dojo strip
Scroll to Top