AnalystPath

Flip the Winning Side

SQLEasyJunior level~15 min

Problem

Table: `chess_match`

| Column Name | Type |
|---|---|
| match_id | int |
| event | varchar |
| winner_side | char(1) |
| moves | int |

`match_id` is the primary key. `winner_side` is always one of two values: `'w'` (white) or `'b'` (black).

The board photos were mirrored during data entry, so every recorded side is backwards. Produce a corrected result set that turns every `'w'` into `'b'` and every `'b'` into `'w'`, keeping `winner_side` as the column alias. Return all four columns ordered by `match_id`.

Tables

Example rows — the live problem includes the full dataset.

chess_match
match_ideventwinner_sidemoves
1Round Aw41
2Round Ab28
3Round Bw55

Expected output

Your answer should return 4 rows with the columns match_id, event, winner_side, moves.

Starter code (SQL)

SELECT *
FROM chess_match;

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