BeginnerCoder

Lesson 5 — UNION

UNION vs UNION ALL

UNION stacks the results of two SELECTs on top of each other and removes duplicates. UNION ALL keeps every row, duplicates included (and is faster). Both SELECTs must return the same number of columns.

SELECT email FROM customers
UNION
SELECT email FROM newsletter

Why it matters: combining lists from different tables ("everyone we can contact") is common — and choosing UNION vs UNION ALL decides whether people get the email twice.

Want it another way?
Task

Change UNION ALL to UNION so each email appears once. Expected: 4 unique emails.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.