sql - two foreign keys to same primary key select statement MYSQL -
first table "teams" has teamcode(varchar 5) , teamname (varchar 20) second table "season" has hometeam (varchar 5) , team2 (varchar 5), gameday (date)
hometeam & team2 fks connected teamcode pk
table: teams
| teamcode | teamname |
|:-----------:|:--------------|
| 1 | usa |
| 2 | uk |
| 3 | japan |
table: season
each team plays other once home team
| team1 | team2 |gameday |:-----:|:------|:------| | 1 | 2 | 7 jan| | 1 | 3 | 14 jan| | 2 | 1 | 21 jan| | 2 | 3 | 28 jan| | 3 | 1 | 4 feb| | 3 | 2 | 11 feb|
i want query display team names , day play together
so should like
hometeam name | team2 name | gameday
try this
select t1.name host , t2.name guest, s.date [dbo].[season] s inner join [dbo].[team] t1 on s.hostteam = t1.id inner join [dbo].[team] t2 on s.guestteam = t2.id
Comments
Post a Comment