Back to Practice
#0357
Deduplicate Events Keep First
MediumSQL24 min20 XP
Problem
For duplicate events by user_id and event_name, return the earliest event_id.
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
events(event_id INTEGER, user_id INTEGER, event_name TEXT, event_time TEXT)
Examples
Example 1
Inputtwo click events for user 1
Outputearliest click only
ROW_NUMBER ranks duplicates by event_time.
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
Inputtwo click events for user 1
Expected[[2,1,"click"],[3,1,"view"]]
ROW_NUMBER ranks duplicates by event_time.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks