5 SQL Interview Questions That Trip Up Beginners

If you're prepping for a tech interview, SQL usually feels "easy" until you're actually in the room. Here are 5 questions that look simple on paper but catch people off guard — plus quick explanations so you don't get caught out.

1. What's the difference between WHERE and HAVING?

Most people say "WHERE filters rows, HAVING filters groups" and stop there — which is correct, but interviewers often follow up with: why can't you use an aggregate function like COUNT() inside WHERE?

The answer: WHERE is applied before GROUP BY, while the aggregate values don't exist yet at that stage. HAVING runs after grouping, once the aggregates are calculated. That's why: