UNION vs UNION ALL

Updated May 4, 2026

Short answer

UNION removes duplicates; UNION ALL keeps all rows.

Deep explanation

UNION requires an internal sort and distinct operation, making it slower. UNION ALL is faster and should be used if duplicates are okay or impossible.

Real-world example

Merging two historical data sets for a report.

Common mistakes

  • Using UNION when duplicates are not possible, wasting CPU on distinct checks.

Follow-up questions

  • Must column counts match?

More MySQL interview questions

View all →