Players Whose Coach Left the Roster
Problem
Table: `roster`
| Column Name | Type |
|---|---|
| player_id | int |
| full_name | varchar |
| coach_id | int |
| stipend | int |
`player_id` is the primary key. Each row gives a player, their monthly stipend, and the `player_id` of their coach (a coach is also listed as a player). Some players have no coach (`coach_id` is NULL).
Return the `player_id` of every player whose stipend is strictly below `2000` and whose coach is no longer on the roster. A coach is no longer on the roster when their id does not appear as any `player_id`. Order the result by `player_id` ascending.
Tables
Example rows — the live problem includes the full dataset.
| player_id | full_name | coach_id | stipend |
|---|---|---|---|
| 1 | Ana | 5000 | |
| 2 | Beto | 1 | 1500 |
| 3 | Cleo | 9 | 1200 |
Expected output
Your answer should return 2 rows with the columns player_id.
Starter code (SQL)
SELECT *
FROM roster;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock