# 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

## Problem

The growth team is targeting dormant accounts that have never logged a session. Return the user ID and username for every user with zero session history.

## 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). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.