When is DISTINCT the wrong tool compared with GROUP BY?
PICTURE THIS: DATABASE INDEX
Simple meaning
DISTINCT removes duplicate full rows but does not compute sums, and it can hide that you joined explosively and then deduped.
WHY — SQL Analytics instead of guessing?
Why interviewers care about SQL Analytics:
on SQL Analytics.
the situation, the default choice, and one exception - that reads as experience.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens step by step?
Before you speak the answer, walk the interviewer through these steps:
- 1DISTINCT removes duplicate full
rows but does not compute sums, and it can hide that you joined explosively and then deduped.
- 2GROUP BY with aggregates
is the honest way to define metrics at a grain.
- 3If you need one
row per user, group on user_id and choose an aggregation rule, not a random remaining row.
- 4Give an example
One tiny concrete case you can say aloud.
- 5Common mistake
What juniors usually get wrong.
- 6Close
When you pick this over the alternative.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
DISTINCT removes duplicate full rows but does not compute sums, and it can hide that you joined explosively and then deduped. GROUP BY with aggregates is the honest way to define metrics at a grain.