UNION Operator
Question
What does UNION do?
Hint
UNION ALL is faster because it does not remove duplicates.
Explanation
UNION combines the result sets of two or more SELECT queries into a single result set, removing duplicates. UNION ALL keeps duplicates and is faster. Requirements: both queries must return the same number of columns with compatible types. SELECT name FROM employees UNION SELECT name FROM contractors returns all unique names. UNION is useful for combining data from similar tables, multi-source searches, and reporting. ORDER BY applies to the combined result and goes at the end. UNION can be slower than UNION ALL due to deduplication.
Related Resources
Related Lessons
- SELECT
Learn SELECT.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.