SQL Replace multiple variables from another table in query result

后端 未结 1 1045
别跟我提以往
别跟我提以往 2020-12-17 03:27

I have a team schedule table that looks like this:

DBO.SCHEDULE

Game1_Time  |  Game1_Home_Team   | Game1_Away_Team 
=================================         


        
相关标签:
1条回答
  • 2020-12-17 03:53

    basically just do two joins one for the home name and one for the away name.

    SELECT 
         s.Game1_Time, 
         t.Team_Name as 'Home Team', 
         t1.Team_Name as 'Away Team'
    FROM `SCHEDULE` s
    JOIN `TEAM` t on t.Team_Number = s.Game1_Home_Team
    JOIN `TEAM` t1 on t1.Team_Number = s.Game1_Away_Team
    

    i added backticks because schedule is a keyword so just to not mess anything up you should use backtics on the tablename

    DEMO

    0 讨论(0)
提交回复
热议问题