AnalystPath

Captain of the Biggest Squad

SQLMediumMid level~15 min

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.

roster
player_idplayer_namesquad_idrole
1Ravi10Captain
2Mei10Member
3Tomas10Member

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

Related SQL questions