I have two SQL tables. The first table stores a list of athletes with their id and name. For example:
athlete_id | first_name | last_name
-----------|------------|----------
1 | Matthew | Reese
2 | Tiffanie | Renz
3 | Tom | Dow
etc...
The second table stores entries for a track (sprint) event, and the id of the athlete competing in each lane. For example:
event_id | lane1_athlete_id | lane2_athlete_id | lane3_athlete_id
---------|------------------|------------------|-----------------
1 | 1 | 15 | 24
2 | 18 | 2 | 4
3 | 78 | 50 | 3
etc...
I need to create an SQL query which will return that second table, but with the athlete ids resolved to the athlete names. For example:
event_id | lane1_athlete | lane2_athlete | lane3_athlete
---------|---------------|---------------|--------------
1 | Matthew Reese | Lesa Allain | Nicole Spiers
2 | Emmy Bartol | Tiffanie Renz | Louise Baier
3 | Zack Bui | Norah Flagg | Tom Dow
I imagine this involves a table join, but I can't get my head around the correct query. Any help would be appreciated.