# Idle Team Members

> Sprint started. Some people never got assigned.

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

Domain: SQL · Difficulty: easy · Seniority: L5 · Asked in: Chubb

## Problem

Each row in `user_sessions` is one session logged against a `user_id` from `users`, and some accounts have never logged a single one. Return the user ID and username of every account with zero session history, lowest user ID first.

## 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 141 rows:

| user_id | username |
| --- | --- |
| 2040 | cynthia |
| 2137 | colin42 |
| 2234 | cara_z |
| 2428 | celine |
| 2525 | daniel |

## Worked solution and explanation

### Why this problem exists in real interviews

Finding users with zero session history tests the anti-join pattern. The interviewer checks whether you correctly identify the absence of related records.

---

### Break down the requirements

#### Step 1: Left join users to sessions

`LEFT JOIN user_sessions ON users.user_id = user_sessions.user_id` preserves all users, including those with no sessions.

#### Step 2: Filter for unmatched users

`WHERE user_sessions.user_id IS NULL` isolates users with no session history.

---

### The solution

**Anti-join for users with no sessions**

```sql
SELECT u.user_id, u.username
FROM users u
LEFT JOIN user_sessions s ON u.user_id = s.user_id
WHERE s.user_id IS NULL
ORDER BY u.user_id
```

> **Cost Analysis**
>
> Standard anti-join. An index on `user_sessions(user_id)` makes the join efficient.

> **Interviewers Watch For**
>
> The interviewer watches for the anti-join pattern. NOT EXISTS is also correct.

> **Common Pitfall**
>
> `NOT IN (SELECT user_id FROM user_sessions)` fails if any `user_id` is NULL.

---

## Common follow-up questions

- How would you show how long each idle user has been registered? _(Tests date arithmetic on `signup_date`.)_
- What if idle means no sessions in 30 days (not ever)? _(Tests date filter in the LEFT JOIN ON clause.)_
- How would you count idle vs. active users? _(Tests conditional aggregation or UNION.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/idle_team_members)
- [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.