SQL Replace multiple variables from another table in query result

I have a command schedule table that looks like this:

DBO.SCHEDULE

Game1_Time  |  Game1_Home_Team   | Game1_Away_Team 
===================================================
12:00:00    |         1          |         2

      

I want to replace the command values ​​with the corresponding command that exists in another table:

DBO.TEAM

Team_Number  |  Team_Name
========================
    1        |  The Monsters
    2        |  Bug Bites

      

TRYING TO DO THIS: How to replace 1 and 2 in the Monsters and Bug Bites list in the query result?

Game1_Time  |  Home Team         | Away Team 
===================================================
12:00:00    |  The Monsters      |  Bug Bites

      

+3


source to share


1 answer


basically just two combinations of one for a home name and a name for a 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 backlinks because schedule is a keyword so just don't need to confuse anything, you should use backtics on tablename

DEMO

+5


source







All Articles