SQL UNION ALL Keyword
The UNION ALL command combines the result sets of two or more SELECT statements into a single result set. Unlike UNION, it does not remove duplicate values — all matching rows from both queries are included.
SQL UNION ALL Syntax
SQL
x
1
SELECT column1, column2, ...
2
FROM table1
3
UNION ALL
4
SELECT column1, column2, ...
5
FROM table2
6
ORDER BY column_name;
SQL UNION ALL Example
This query combines all gender
values from Patients
and all specialty
values from Doctors
, including any duplicates.
SQL
1
1
SELECT gender AS info
2
FROM Patients
3
UNION ALL
4
SELECT specialty
5
FROM Doctors
6
ORDER BY info;
