# The Waiting Room

> Signed up. Never verified. Never came back.

Canonical URL: <https://datadriven.io/problems/the_waiting_room>

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.

## Tables

### users

- user_id INTEGER
- username TEXT
- email TEXT
- signup_date TEXT
- account_status TEXT
- age_bucket TEXT

Sample rows (10 of 200):

| user_id | username | email | 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

- session_id INTEGER
- user_id INTEGER
- device_id INTEGER
- session_start TEXT
- session_duration_sec INTEGER
- pages_viewed INTEGER

Sample rows (10 of 200):

| 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

First 5 of 47 rows:

| user_id | username | email | 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

**PENDING USERS WITH NO MARCH SESSIONS**

```sql
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 NULL
```

> **One month of partitions, not forty million rows**
>
> 8M users LEFT JOIN 40M sessions. Partitioning by `session_start` prunes to one month of files. A composite index on (`user_id`, `session_start`) keeps lookups cheap; IS NULL costs nothing once joined.

> **Why the date lives in `ON`**
>
> Whether you can articulate why the date filter belongs in `ON`. Naming the anti-join pattern and noting `NOT EXISTS` as an equivalent, often-faster rewrite.

> **Text months compare to text**
>
> `strftime` returns text, so compare to '03', not 3. The integer comparison fails every row and silently flips the result to every pending account, regardless of activity.

> **A right-side `WHERE` undoes the outer join**
>
> First instinct is to put `strftime('%m', us.session_start) = '03'` in `WHERE`. That turns the `LEFT JOIN` into an `INNER JOIN`: unmatched rows have NULL `session_start` and fail equality. Pivot to keeping month and year inside `ON`.

---

### COMMON 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.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/the_waiting_room)
- [SQL Interview Questions](https://datadriven.io/sql-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). DataDriven is the data engineering interview community. Live code execution in SQL, Python, and Spark sandboxes. Every feature is open to every member.