Interview Q&A · SQL · 12 questions in this topic
Rapid-Fire Revision — SQL Interview Q&A
One-line answers spanning the whole bank — the final pass the night before the interview. Part of Scenarios & Rapid Fire · 192 questions in the SQL bank.
This rapid-fire round condenses the SQL bank into short, testable answers. The cards cover distinctions that show up in screening rounds: WHERE versus HAVING, INNER versus LEFT JOIN, NULL comparison, and when a subquery becomes a window function. Treat each answer as a prompt for a small query you could write on a whiteboard, and open the linked topic when you need the full example rather than the summary. For each card, also name the clause that runs first and the row set it sees — that ordering explains most surprises.
Execution order?
Answer
FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT.
WHERE vs HAVING?
Answer
WHERE filters rows before grouping; HAVING filters groups after.
Why does = NULL fail?
Answer
NULL comparisons yield UNKNOWN, never TRUE — use IS NULL.
NOT IN trap?
Answer
One NULL in the set returns zero rows — use NOT EXISTS.
COUNT(*) vs COUNT(col)?
Answer
COUNT(*) counts rows; COUNT(col) skips NULLs.
UNION vs UNION ALL?
Answer
UNION dedups (costly); UNION ALL keeps everything (fast).
INNER vs LEFT JOIN?
Answer
INNER keeps matches only; LEFT keeps all left rows with NULLs for misses.
ON vs WHERE in LEFT JOIN?
Answer
ON preserves outer rows; WHERE on the nullable side silently makes it INNER.
Nth salary?
Answer
DENSE_RANK() OVER (ORDER BY salary DESC), filter = N.
ROW_NUMBER vs RANK vs DENSE_RANK?
Answer
Unique numbering; ties with gaps; ties without gaps.
Sargable predicate?
Answer
Bare column vs value — index-seekable; functions on columns force scans.
Prevent SQL injection?
Answer
Parameterized queries always — never interpolate input into SQL text.
Recommended resourcesAffiliate links · may earn us a commission