CHAPTER 17
Combining results from multiple queries into a single result set.
π 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).
SQL
SELECT name FROM customers UNION SELECT name FROM employees;
Combine results including duplicates.
SQL
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.