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
SELECT column1, column2, ... FROM table1 UNION ALL SELECT column1, column2, ... FROM table2 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.
SELECT gender AS info FROM Patients UNION ALL SELECT specialty FROM Doctors ORDER BY info;
