SQL Practice Problem #022

Combine email lists without duplicates

Return a single list of email addresses from customers and newsletter_signups without duplicates.

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

newsletter_signups

Output

Expected Output

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