AnalystPath

Valid Relay Teams Across Three Clubs

SQLEasyJunior level~15 min

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.

ClubNorth
swimmer_idswimmer_name
1Mara
2Niko
ClubEast
swimmer_idswimmer_name
3Otis
ClubWest
swimmer_idswimmer_name
3Otis
2Pia
10Mara

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

Related SQL questions