Interview prep

SQL Interview Questions

SQL screens are near-universal for data and backend roles. Joins, window functions and query plans cover most of it.

Questions and answers

01Difference between INNER JOIN and LEFT JOIN?

INNER returns only matched rows; LEFT keeps every row from the left table and fills unmatched right-side columns with NULL. Filtering the right table in WHERE silently turns a LEFT JOIN back into an INNER JOIN.

02What is a window function?

An aggregate evaluated over a defined window of rows without collapsing them — ranking, running totals and period-over-period comparisons.

03How do indexes speed up queries, and when do they hurt?

They give sub-linear lookups on the indexed columns but add write cost and storage. Low-cardinality columns and heavily written tables are where they stop paying off.

04Explain the difference between WHERE and HAVING.

WHERE filters rows before aggregation; HAVING filters groups after aggregation.

05How do you find and fix a slow query?

Read EXPLAIN ANALYZE for the plan, look for sequential scans on large tables and bad row estimates, then add or fix indexes, rewrite correlated subqueries and update statistics.

How to answer these well

Interviewers are not grading recall — they are checking whether you've hit the failure mode the question describes. Anchor every answer to something you actually shipped or debugged with SQL.

Say the trade-off out loud. "I'd use X here, but it costs Y under Z conditions" scores higher than a clean textbook definition every time.

Roles asking for SQL

Related prep