Scouts Who Earned Every Badge
Problem
Table: `earned`
| Column Name | Type |
|---|---|
| scout_id | int |
| badge_code | int |
This table may contain duplicate rows. `scout_id` is never NULL and `badge_code` references the `badge` table.
Table: `badge`
| Column Name | Type |
|---|---|
| badge_code | int |
`badge_code` is the primary key.
Report the `scout_id` of every scout who has earned **all** of the badges listed in the `badge` table. Return the result in any order.
Tables
Example rows — the live problem includes the full dataset.
| scout_id | badge_code |
|---|---|
| 1 | 50 |
| 2 | 60 |
| 3 | 50 |
| badge_code |
|---|
| 50 |
| 60 |
Expected output
Your answer should return 2 rows with the columns scout_id.
Starter code (SQL)
SELECT *
FROM earned;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