你好我有两个foreigns键名称可视化的问题。我在database
开发足球sql
,这是relationship diagram
这是我的Select Query
:
Select team.Name, comp.Name,comp.Stage,fixDate.Date,news.Description
FROM Fixtures fix
Join Competition comp
On fix.CompetitionID = comp.ID
Join FixtureDate fixDate
On fix.FixtureDateID=fixDate.ID
Join News news
On news.ID = fix.NewsId
Join Teams team
On fix.AwayTeamID = team.ID;
问题是我不知道如何可视化homeTeam名称和awayTeam名称。我试试
On fix.AwayTeamID = team.ID AND fix.HomeTeamID = team.ID
但输出为空响应..
以下是只有一个团队名称的输出
但是我想展示和他的对手客场球队。 谢谢你的建议!答案 0 :(得分:1)
为此需要两个带表别名的连接。
Select team1.Name, team2.Name, comp.Name, comp.Stage, fixDate.Date, news.Description
FROM Fixtures fix
Join Competition comp
On fix.CompetitionID = comp.ID
Join FixtureDate fixDate
On fix.FixtureDateID=fixDate.ID
Join News news
On news.ID = fix.NewsId
Join Teams team1
On fix.HomeTeamID = team1.ID
Join Teams team2
On fix.AwayTeamID = team2.ID;