SQL LEARNING PLATFORM
Combining results from multiple queries into a single result set.
Learning Blocks
Interactive Queries
Concepts you'll master
UNION is used to combine results of two or more SELECT queries
Each SELECT must have the same number of columns
Column data types must be compatible
UNION removes duplicate rows by default
Use UNION ALL to include duplicates
π Think of it this way: You have two lists β one of customers and one of employees. UNION merges them into a single list. Itβs like stacking results on top of each other.
Combine customer names and employee names into one list (duplicates removed).
SELECT name FROM customers UNION SELECT name FROM employees;
Combine results including duplicates.
SELECT name FROM customers UNION ALL SELECT name FROM employees;
β Pro Tip: Use UNION when you want unique results. Use UNION ALL when performance matters and duplicates are allowed.
Practice your SQL skills