UNION ALL Operator - SQL


Overview


The UNION ALL Operator in SQL is used to combine the result sets of two or more SELECT statements into a single result set, including all duplicate rows.

Syntax:

SELECT column1, column2
FROM table1
UNION ALL
SELECT column1, column2
FROM table2

SELECT column1, column2, ... FROM table1 specifies the columns to select from the first table.

UNION ALL combines the results of the two SELECT statements, including duplicates.

SELECT column1, column2, ... FROM table2 specifies the columns to select from the second table. The number and data types of columns in both SELECT statements must match.