Back to Practice
#0395
Latest Status Per Order
MediumSQL24 min20 XP
Problem
Return order_id and status for each order’s latest status update.
Why This Matters
SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.
Schema
order_status(order_id INTEGER, status TEXT, updated_at TEXT)
Examples
Example 1
Inputorder 1 latest status is paid
Outputorder 1 paid
The latest row is rank 1 when ordered by updated_at descending.
Constraints
- Return only the requested columns.
- Use deterministic ORDER BY when multiple rows are returned.
- Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Inputorder 1 latest status is paid
Expected[[1,"paid"],[2,"created"]]
The latest row is rank 1 when ordered by updated_at descending.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks