Data

SQL interview questions & practice path

Joins, aggregation, window functions, and performance reasoning. Learn what interviewers probe, drill the questions until answers come fast, then prove it in a scored mock, all in one SQL path inside Round Zero.

  • Concept lessons that explain the why, not just the answer
  • Practice questions with adaptive follow-ups and flashcards
  • A scored mock with evidence quoted from your own answers

Sample SQL questions

What a strong answer covers, and the mistakes interviewers watch for. The scored path drills every one with live follow-ups.

What is the difference between WHERE and HAVING?

easy

A strong answer covers

  • WHERE filters individual rows before grouping; HAVING filters groups after GROUP BY has aggregated them.
  • Aggregate functions (COUNT, SUM, AVG) can appear in HAVING but not in WHERE, because aggregates don't exist yet at row-filtering time.
  • Logical evaluation order: FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY.
  • Performance note: filtering early in WHERE shrinks the working set before the (more expensive) grouping step.

Common mistakes

  • Saying they're interchangeable, or that HAVING is just 'WHERE for GROUP BY' without mentioning aggregates.
  • Putting an aggregate condition in WHERE and expecting it to work.
  • Not knowing the logical clause evaluation order when pressed on why.

Explain the difference between INNER, LEFT, RIGHT, and FULL OUTER JOIN. When would you reach for each?

easy

A strong answer covers

  • INNER returns only matching rows; LEFT keeps every left row and NULL-fills missing right matches; RIGHT is the mirror; FULL OUTER keeps both sides.
  • Concrete use cases: LEFT JOIN for 'all customers including those with zero orders'; INNER for 'only customers who ordered'.
  • Row-count intuition: joins can multiply rows when the join key isn't unique on one side — a classic silent-bug source.
  • A strong answer sketches a two-table example and states what each join returns for it.

Common mistakes

  • Only defining the joins without a use case for choosing one.
  • Missing that a one-to-many join duplicates rows and inflates downstream aggregates.
  • Confusing which side LEFT preserves.

What are window functions? Write a query giving each employee's salary rank within their department.

medium

A strong answer covers

  • Window functions compute across a set of related rows without collapsing them the way GROUP BY does — every input row survives.
  • Anatomy: function OVER (PARTITION BY ... ORDER BY ...); PARTITION resets the window, ORDER defines ranking/frame order.
  • Example: SELECT name, dept, salary, RANK() OVER (PARTITION BY dept ORDER BY salary DESC) FROM employees;
  • Knows RANK vs DENSE_RANK vs ROW_NUMBER tie-handling differences.

Common mistakes

  • Reaching for GROUP BY + self-join when a window function is the direct answer.
  • Forgetting PARTITION BY so the rank is global instead of per-department.
  • Not knowing how ties behave across RANK/DENSE_RANK/ROW_NUMBER.

Find the second-highest salary in a table — and make it robust to duplicates and to there being no second salary.

medium

A strong answer covers

  • Clean approach: SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1 — DISTINCT handles duplicate top salaries.
  • Alternative: MAX(salary) WHERE salary < (SELECT MAX(salary) ...), or DENSE_RANK() = 2 in a subquery for 'nth' generality.
  • Robustness: returns NULL/empty when only one distinct salary exists — a strong answer says what happens and how the caller should handle it.
  • Generalizes the pattern to nth-highest and mentions the trade-offs between the approaches.

Common mistakes

  • LIMIT 1 OFFSET 1 without DISTINCT — breaks when the top salary is duplicated.
  • Not addressing the empty/one-row edge case at all.
  • Hardcoding for 'second' with no idea how to generalize to nth.

A production query has become slow. Walk me through how you'd diagnose and fix it.

hard

A strong answer covers

  • Start with evidence: EXPLAIN/EXPLAIN ANALYZE to see the actual plan — scans vs index use, join strategy, row estimates vs reality.
  • Common culprits: missing/unused indexes, functions wrapping indexed columns, leading-wildcard LIKE, SELECT *, stale statistics, exploding joins.
  • Fix ladder: right index (including composite/covering), query rewrite, then schema-level answers (denormalization, materialized views, partitioning).
  • Mentions verifying the fix under production-like data volume, and that adding an index costs write performance.

Common mistakes

  • Jumping straight to 'add an index' without reading a query plan first.
  • No mention of EXPLAIN at all.
  • Ignoring that recent data growth or plan changes — not the query text — are often what changed.

How SQL answers are scored

Correctness

40%

Produces queries and explanations that are logically correct, including edge cases like NULLs and duplicates.

Conceptual depth

30%

Explains why — how the engine evaluates clauses, when indexes help, what a window function does under the hood.

Communication

30%

Walks through reasoning clearly, states assumptions, and structures the answer before diving in.

Role tracks that include SQL

Related Data skills

All skills →

No spam. Unsubscribe anytime.

Ready to master SQL?

Sign up free. Your SQL path includes lessons, drills, flashcards, and a scored mock with feedback on what to fix.

  • Concept lessons plus practice questions
  • Flashcards for spaced repetition
  • A scored mock with evidence quotes

Questions & answers

What SQL interview questions should I practice?
Start with the core areas SQL interviewers probe: What is the difference between WHERE and HAVING; Explain the difference between INNER, LEFT, RIGHT, and FULL OUTER JOIN. When would you reach for each; What are window functions? Write a query giving each employee's salary rank within their department.. This page outlines strong answers and common mistakes, and the scored path drills each one with follow-ups.
Is the SQL practice free?
Yes, you can start a SQL path free inside Round Zero. It generates lessons, practice questions, flashcards, and a scored mock. Sign up to unlock the full drills and your evidence-backed scorecard.
How is this different from a SQL question list?
A static list gives you questions with no feedback. Round Zero runs a live scored practice that probes your actual answers, rotates difficulty, and tells you exactly what to fix, grounded in a SQL rubric.
How should I prepare for a SQL interview?
Learn the concepts, drill the questions until answers come fast, then prove it in a scored mock. Round Zero sequences all three so you know you are ready, not just that you read about SQL.
How is a SQL answer scored?
SQL answers are scored on correctness, conceptual depth, communication, with evidence quoted from what you actually said, so feedback is specific instead of generic praise.