QUESTION 1 OF 10

When is WHERE evaluated relative to GROUP BY?

Reveal the answer and explore the explanation.

01
EasyCore

When is WHERE evaluated relative to GROUP BY?

Answer
Answer

Filters input rows before grouping in logical query processing.

Practical example

Select attempts from the last month before aggregating.

SQLRelated concept example
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.

Reference: Further reading ↗

Last 30 min revisionHigh-yield interview Q&As