Sobes.tech
Junior — Middle

Can you explain what the UNION ALL operator means in SQL and how it works?

sobes.tech AI

Answer from AI

The UNION ALL operator in SQL combines the results of two or more queries, returning all rows from each query, including duplicates.

Unlike UNION, which removes duplicate rows, UNION ALL keeps all, making it faster as it does not require an additional operation to remove duplicates.

Example:

SELECT name FROM employees
UNION ALL
SELECT name FROM managers;

This query will return a list of all names from the employees and managers tables, including duplicate names if they exist in both tables.