The Waiting Room
An easy SQL interview practice problem on DataDriven. Write the query and run it against a real database, with instant feedback.
- Domain
- SQL
- Difficulty
- easy
- Seniority
- L3
- Asked in
- Meta
Problem
Sessions in any other month don't matter: what makes an account idle here is zero sessions in user_sessions during March 2026. Pull the full users profile of every account still in 'pending_verification' status that was idle by that measure.
Signed up. Never verified. Never came back.
Tables
users
Columns: user_id INTEGER, username TEXT, email TEXT, signup_date TEXT, account_status TEXT, age_bucket TEXT
| user_id | username | signup_date | account_status | age_bucket | |
|---|---|---|---|---|---|
| 100 | alice | alice@example.com | 2025-02-02 | inactive | 25-34 |
| 197 | aaron42 | aaron42@example.com | 2026-03-03 | suspended | 35-44 |
| 294 | amelia | amelia@example.com | 2024-04-04 | pending_verification | 45-54 |
| 391 | arjun | arjun@example.com | 2025-05-05 | active | 55-64 |
| 488 | ava99 | ava99@example.com | 2026-06-06 | inactive | 65+ |
| 585 | andrew_k | andrew_k@example.com | 2024-07-07 | suspended | NULL |
| 682 | anika | anika@example.com | 2025-08-08 16:34:00 | pending_verification | 18-24 |
| 779 | aiden | aiden@example.com | 2026-09-09 14:53:00 | active | 25-34 |
| 876 | aria_b | aria_b@example.com | 2024-10-10 | inactive | 35-44 |
| 973 | brian | brian@example.com | 2025-11-11 | suspended | 45-54 |
user_sessions
Columns: session_id INTEGER, user_id INTEGER, device_id INTEGER, session_start TEXT, session_duration_sec INTEGER, pages_viewed INTEGER
| session_id | user_id | device_id | session_start | session_duration_sec | pages_viewed |
|---|---|---|---|---|---|
| 7061 | 197 | 230 | 2026-02-02 01:00:00 | 53 | 3 |
| 7122 | 294 | 259 | 2026-03-03 02:00:00 | 76 | 6 |
| 7183 | 391 | 288 | 2026-04-04 03:00:00 | 99 | 9 |
| 7244 | 488 | 317 | 2026-05-05 04:00:00 | 122 | 12 |
| 7305 | 585 | 346 | 2026-06-06 05:00:00 | 145 | 15 |
| 7366 | 682 | 375 | 2026-07-07 06:00:00 | 168 | 18 |
| 7427 | 779 | 404 | 2026-08-08 07:00:00 | 191 | 21 |
| 7488 | 876 | NULL | 2026-09-09 08:00:00 | 214 | 24 |
| 7549 | 973 | 462 | 2026-01-10 09:00:00 | 237 | 27 |
| 7610 | 1070 | 491 | 2026-02-11 10:00:00 | 260 | 30 |
Expected output
| user_id | username | signup_date | account_status | age_bucket | |
|---|---|---|---|---|---|
| 682 | anika | anika@example.com | 2025-08-08 16:34:00 | pending_verification | 18-24 |
| 1070 | bjorn99 | NULL | 2026-03-12 | pending_verification | 55-64 |
| 2234 | cara_z | cara_z@example.com | 2026-06-24 | pending_verification | 35-44 |
| 2622 | derek | derek@example.com | 2024-04-28 | pending_verification | NULL |
| 3010 | dimitri | dimitri@example.com | 2025-08-04 | pending_verification | 45-54 |
Worked solution and explanation
What this is really asking
This is an anti-join wearing a verification-queue costume: find the pending accounts with no March footprint. Anyone can write the LEFT JOIN. The move that separates candidates is knowing the March date filter has to ride inside the ON clause, not WHERE. Slip it into WHERE and every unmatched row (NULL session_start) fails the equality, the outer join silently degrades to an inner join, and your 'inactive' list quietly becomes 'active in March' instead.
Break down the requirements
Step 1: Anti-join on user_sessions
LEFT JOIN to user_sessions and keep rows where us.session_id IS NULL. That isolates accounts with zero matched March sessions.
Step 2: Scope the join to March
Push year and month into ON so an account active in February still qualifies if March was empty.
Step 3: Filter on status
account_status = 'pending_verification' is safe in WHERE: it touches only the left side, so it can never drop an unmatched row.
The solution
SELECT u.user_id, u.username, u.email, u.signup_date,
u.account_status, u.age_bucket
FROM users u
LEFT JOIN user_sessions us
ON u.user_id = us.user_id
AND strftime('%Y', us.session_start) = '2026'
AND strftime('%m', us.session_start) = '03'
WHERE u.account_status = 'pending_verification'
AND us.session_id IS NULLCOMMON FOLLOW-UP QUESTIONS
Common follow-up questions
- Rewrite this with NOT EXISTS instead of LEFT JOIN. (Tests the anti-join alternative and when each plan wins on 40M sessions.)
- Extend this to flag accounts inactive for any calendar month, not just March. (Forces a per-account MAX(`session_start`) or calendar-driven join, exposing parameterization.)
- What if `user_sessions` is append-only and lags by an hour? (Opens freshness: compute on a cutoff timestamp or accept the lag in the queue.)