Advertisements
I have a database like in the attached picture
I want to make a query that will display:
Home | Away | Score home | Score away | Date |
---|---|---|---|---|
TeamName1 | TeamName3 | 3 | 2 | 2023-03-15 |
TeamName2 | TeamName1 | 0 | 1 | 2023-03-10 |
TeamName3 | TeamName2 | 2 | 2 | 2023-03-09 |
TeamName1 | TeamName4 | 4 | 3 | 2023-03-13 |
Please help. Thank you in advance.
I’m learning sql and I can’t deal with this query.
>Solution :
Based on the input table structure, you should use JOIN operator to get home and away team name for the result.
Here is the query:
SELECT
h.name as home,
a.name as away,
g.score_home,
g.score_away,
g.date
FROM
games g
JOIN
team h
ON
g.id_team_home = h.id_team
JOIN
team a
ON
g.id_team_away = a.id_team