Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. UNION vs UNION ALL

SQL · Basics & Joins

UNION vs UNION ALL

Easysql-04
unionset operationsduplicates

Question

What is the difference between UNION and UNION ALL?

Solution

UNION combines results and removes duplicates.

UNION ALL combines results and keeps duplicates.

SELECT city FROM customers
UNION
SELECT city FROM suppliers;

Duplicates are removed.

SELECT city FROM customers
UNION ALL
SELECT city FROM suppliers;

Duplicates remain.

Which is faster?

Usually UNION ALL, because it doesn't need to perform duplicate elimination.

Use:

  • UNION → when duplicates must be removed
  • UNION ALL → when you know duplicates are valid or don't care about them

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext