Intermediatehow it works
How do you keep only the latest record per key?
Quick answerFree
ROW_NUMBER() OVER (PARTITION BY key ORDER BY updated_at DESC, tie_breaker DESC) in a CTE, then keep rn = 1. Mention the tie-breaker so the result is deterministic, and that in a warehouse you might use QUALIFY where supported.
Detailed answer· 40 words
Interview PrepUnlock the full answer with Interview Prep
Get a 40-word model answer, 3 key points and a visual explainer, plus 247 more SQL questions.
Also in Pro (₹499 / 90 days).
Key points· 3 points
Interview PrepUnlock with Interview Prep
Visual explainer· animated, step by step
Interview PrepUnlock with Interview Prep
+ 247 more SQL questions in Interview Prep, each with the full answer.