Problem
Task
Return a single list of email addresses from customers and newsletter_signups without duplicates.
Schema
Table Schema
customers(id, email)
newsletter_signups(id, email)
Input
Sample Data
customers
| id | |
|---|---|
| 1 | alice@example.com |
| 2 | bob@example.com |
newsletter_signups
| id | |
|---|---|
| 10 | bob@example.com |
| 11 | chloe@example.com |
Output
Expected Output
| alice@example.com |
| bob@example.com |
| chloe@example.com |
Answer
Check Your Solution
Show Answer and Explanation
Correct Answer
SELECT email
FROM customers
UNION
SELECT email
FROM newsletter_signups
ORDER BY email;
Explanation
UNION combines two result sets and removes duplicate rows. Because both SELECT statements return one email column, the sets are compatible. ORDER BY makes the final list stable.
Common Mistakes
- Using UNION ALL when duplicates should be removed.
- Selecting different numbers of columns on the two sides.
- Expecting UNION to preserve source-table ordering.
Concepts
Related Concepts
UNION
Set Operators
Duplicate Handling
Set Operator
Duplicates