Valid Relay Teams Across Three Clubs
Problem
A swim relay must field exactly one swimmer from each of three clubs. A relay line-up is valid only if no two of the three chosen swimmers share the same swimmer id **and** no two share the same name.
Each of `ClubNorth`, `ClubEast`, `ClubWest` has columns:
- `swimmer_id` (int)
- `swimmer_name` (varchar)
Return every valid line-up as three columns `leg_north`, `leg_east`, `leg_west` holding the swimmer names. Rows may be in any order.
Tables
Example rows — the live problem includes the full dataset.
| swimmer_id | swimmer_name |
|---|---|
| 1 | Mara |
| 2 | Niko |
| swimmer_id | swimmer_name |
|---|---|
| 3 | Otis |
| swimmer_id | swimmer_name |
|---|---|
| 3 | Otis |
| 2 | Pia |
| 10 | Mara |
Expected output
Your answer should return 2 rows with the columns leg_north, leg_east, leg_west.
Starter code (SQL)
SELECT *
FROM ClubNorth;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