Back to Practice
#0313
Distinct Active Users
EasySQL15 min10 XP
Problem
Return distinct user_id values that appear in events, ordered by user_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)
Examples
Example 1
Inputevents with repeated users
Output10, 11, 12
DISTINCT returns each user only once.
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
Inputevents with repeated users
Expected[[10],[11],[12]]
DISTINCT returns each user only once.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks