SQL • LESSON 23
UNION
Learn how to combine the results of multiple SELECT queries into one result set.
🔴 Advanced⏱ 3 Minutes⭐ 400 XP
🤔 THE QUESTION
How can we combine related columns from multiple tables while keeping every matching relationship?
💡 WHAT IS IT?
A CROSS JOIN combines every row from one table with every row from another table, creating every possible combination.
🎯 WHAT IS IT USED FOR?
It is useful for generating combinations, test data, product-option combinations, calendars, and other situations where every possible pairing is required.
💻 EXAMPLE
SELECT
e.name,
d.department_name
FROM employees e
CROSS JOIN departments d;Mission Brief
Practice using UNION to combine employee and contractor names while removing duplicate values.
Objectives
- ✓ SELECT
- ✓ UNION
- ✓ Multiple queries
- ✓ Result sets
- ✓ Duplicate removal