Javarevisited Newsletter

Javarevisited Newsletter

99% of Developers Get This SQL Question Wrong in Interviews

I’ve been Using SQL UNION Wrong for 3 Years — Here’s What I Learned

javinpaul's avatar
Soma's avatar
javinpaul
and
Soma
Sep 09, 2025
∙ Paid
16
3
Share
99% of Developers Get This SQL Question Wrong in Interviews

The Question That Breaks Confident Developers

“What’s the difference between UNION and UNION ALL?”

It seems simple enough. Most developers confidently start explaining: “UNION removes duplicates, UNION ALL doesn’t.” Then the interviewer asks the follow-up that changes everything:

“When would you use each one?”

That’s when the stumbling begins.

I’ve conducted over 200 technical interviews in the past five years, and this exact scenario plays out repeatedly. Developers who can write complex joins and optimize query plans suddenly go quiet when asked to choose between UNION and UNION ALL in a real-world context.

Here’s what actually happens:

The candidate usually picks UNION “to be safe” — after all, who wants duplicates, right? But that single choice reveals a fundamental misunderstanding that could cost their team thousands in database performance costs.

Btw, if you are preparing for SQL interview questions then you can also see my book Grokking the SQL Interview, you can download a free PDF sample here and also use code friends20 to get 20% discount now.

The Real Problem

It’s not that developers don’t know the technical difference. The issue is they’ve never been taught when and why to use each operator. They memorize the syntax but miss the strategy.

In production systems, choosing UNION over UNION ALL without thinking can:

  • Slow down queries by 300–500%

  • Consume unnecessary memory resources

  • Create bottlenecks that scale poorly

  • Signal to interviewers that you don’t understand performance implications

Keep reading with a 7-day free trial

Subscribe to Javarevisited Newsletter to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
Soma's avatar
A guest post by
Soma
Java and React Developer
Subscribe to Soma
© 2025 javinpaul
Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture