I have the following tables:
Teams
+------+--------------+--------------+
| id | team_name | team_code |
+------+--------------+--------------+
| 1 | Wales | WAL |
| 2 | England | ENG |
| 3 | New Zealand | NZL |
+------+--------------+--------------+
Matches
+------+-----------+-----------+
| id | team_a | team_b |
+------+-----------+-----------+
| 1 | WAL | ENG |
| 2 | ENG | NZL |
| 3 | WAL | NZL |
+------+-----------+-----------+
I know how a join works, but I can’t get my head around how I can query to the database by Matched.id to get the team name for BOTH teams from the Teams database. Let me explain better
- For each match I need to determine the team names
- I will query by
Matches.id - So for Match: 1 I’ll need to select ‘Wales’ and ‘England’
Hope I’ve explained my problem clearly enough, but If I haven’t please feel free to ask more questions
The database structure seems to be “off” to me.
You should have both
team_aandteam_bas foreign keys to theTeamstable primary key.You can then join on the IDs (twice) to get the full names.
Matches: