SQL interview patterns
Practice joins, aggregation, windows and query correctness.
Build query results step by step and validate duplicates, nulls and grouping.
Interview questions
Choose a question to reveal its answer.
01EasyCoreWhen is WHERE evaluated relative to GROUP BY?
Answer
When is WHERE evaluated relative to GROUP BY?
Filters input rows before grouping in logical query processing.
Select attempts from the last month before aggregating.
WITH ranked AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC, id DESC) AS rn FROM test_attempts)
SELECT * FROM ranked WHERE rn = 1;A deterministic tie breaker gives one latest attempt per user.
02EasyCoreHow does COUNT(*) treat null values?
Answer
How does COUNT(*) treat null values?
Counts rows including rows whose individual fields are null.
Count every attempt in a filtered result.
03EasyCoreHow does COUNT(column) differ from COUNT(*)?
Answer
How does COUNT(column) differ from COUNT(*)?
Counts rows where the named expression is not null.
Count only records that have a submitted score.
04MediumHigh priorityHow does DISTINCT remove duplicate rows?
Answer
How does DISTINCT remove duplicate rows?
Eliminates duplicate result rows across the selected expressions.
List unique lesson identifiers.
05MediumHigh priorityWhat is a common table expression?
Answer
What is a common table expression?
Named query expression scoped to a statement.
Break an analytics query into readable intermediate steps.
06MediumHow do you use ROW_NUMBER to find the latest row per group?
Answer
How do you use ROW_NUMBER to find the latest row per group?
Assigns sequential numbers within a window partition according to ordering.
Select the latest attempt for each user.
07MediumHow does RANK handle ties?
Answer
How does RANK handle ties?
Assigns equal ranks to ties and leaves gaps after tied groups.
Rank scores in a competitive list with ties.
08MediumHow does DENSE_RANK handle ties?
Answer
How does DENSE_RANK handle ties?
Assigns equal ranks to ties without gaps.
Find the second highest distinct salary.
09HardWhen should you use COALESCE?
Answer
When should you use COALESCE?
Returns the first non-null expression in its arguments.
Show zero when an aggregate from an outer join is absent.
10HardHow does EXISTS filter rows?
Answer
How does EXISTS filter rows?
Tests whether a subquery returns at least one row.
Find lessons that have at least one completed assessment.
Priority and difficulty are editorial study recommendations.
Technical reference: Documentation / paper ↗
Try a few practice questions
Explore the questions before creating a free account.