Back to Practice
#0327
Latest Login Per User
MediumSQL24 min20 XP
Problem
Return user_id and login_date for each user’s latest login.
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
logins(login_id INTEGER, user_id INTEGER, login_date TEXT)
Examples
Example 1
Inputuser 1 has two logins
Outputlatest login per user
ROW_NUMBER ranks rows inside each user partition.
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
Inputuser 1 has two logins
Expected[[1,"2026-01-05"],[2,"2026-01-03"]]
ROW_NUMBER ranks rows inside each user partition.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks