Code RoomSQL DISTINCT ON misuse
MediumPrep Room Coding #4251

SQL DISTINCT ON misuse

Vibe & agenticDatabases & SQLMid–Senior~18 min

You're auditing a batch of agent-generated data-pipeline PRs as the reviewer-of-record for a team that's leaning hard on AI. This Postgres-targeting query keeps recurring across several PRs, generated to 'deduplicate and keep the latest record per user':

The agent claims it returns the latest row per user. As someone auditing many of these at once, what's specifically wrong, and what review pattern do you put in place so this class of bug doesn't keep slipping through?

Implement
latest_status_per_user(rows: list[str]) → list[str]
Examples
in[["u1|active|2026-01-02","u1|paused|2026-03-04","u2|active|2026-02-02"]]out["u1=paused","u2=active"]
in[["u3|active|","u3|churned|2025-12-31"]]out["u3=churned"]
in[["u2|active|2026-05-05","u1|churned|2026-05-05","u2|paused|2026-05-05"]]out["u1=churned","u2=active"]
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it (tests, edge cases, reading critically), and how you’d re-prompt or decompose to get it right.

0:00 of about 18 min

Vibe & agentic: describe the solution in plain language (or narrate it) and the coach grades your approach.

Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.