Captain of the Biggest Squad
Problem
Table: `roster`
| Column Name | Type |
|---|---|
| player_id | int |
| player_name | varchar(50) |
| squad_id | int |
| role | varchar(30) |
`player_id` is the primary key. Each row is a player belonging to a squad, with a `role` such as 'Captain' or 'Member'. A squad has exactly one captain.
Find the captain of the squad with the most players. If two or more squads tie for the largest size, return the captain of each of them. Output `captain_name` and `squad_id`, ordered by `squad_id`.
Tables
Example rows — the live problem includes the full dataset.
| player_id | player_name | squad_id | role |
|---|---|---|---|
| 1 | Ravi | 10 | Captain |
| 2 | Mei | 10 | Member |
| 3 | Tomas | 10 | Member |
Expected output
Your answer should return 1 row with the columns captain_name, squad_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