Query grain: know what one row represents before joining or aggregating.
SQL Interview Practice for Data Analysts
SQL interviews are not only syntax tests. Strong candidates show that they understand data grain, table relationships, edge cases, and how to prove that a result is trustworthy.
What you’ll practice
Interview preparation works better when you practice the reasoning behind the answer—not just memorize a list of questions.
Joins: reason about cardinality, duplicate multiplication and unmatched records.
Aggregations: use GROUP BY correctly and avoid mixing incompatible grains.
Window functions: ranking, running totals, lag/lead and partitioning.
CTEs and readability: structure a complex answer so another analyst can audit it.
Validation: reconcile row counts, totals and edge cases before trusting the output.
Example interview questions
Use these as prompts, then open the Interview Lab for randomized scenarios and full practice sessions.
Given orders and customers, return one row per customer with their latest completed order and total lifetime revenue.
Why can joining an order-level table to an item-level table inflate revenue, and how would you prevent it?
Write a query that ranks products by monthly revenue within category using a window function.
How would you identify users who placed orders in three consecutive months?
A LEFT JOIN unexpectedly removes rows. What mistake in the WHERE clause could cause that?
How to approach a SQL interview problem
A strong answer usually makes your assumptions visible, defines the grain or metric clearly, and validates the result before recommending action.
State the output grain
Say what one output row should represent. This prevents many join and aggregation mistakes before they happen.
Map the table relationships
Identify one-to-one, one-to-many and many-to-many relationships and decide whether any table needs pre-aggregation.
Build the query in layers
Use small CTEs or subqueries to make filtering, aggregation and ranking steps explicit rather than writing one opaque query.
Handle edge cases deliberately
Consider nulls, ties, duplicate timestamps, cancelled records, missing dimensions and zero-denominator cases.
Validate the result
Check counts and totals against a simpler baseline. In interviews, explaining how you would validate is often as important as the final syntax.
Stop reading questions.
Start answering them.
Open a practice session, answer randomized interview questions, review the explanation, and use the result to decide what to study next.
Open Analyst Interview Lab ↗