Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I make a query (SQL) with two tables?

I have a database like in the attached picture

enter image description here

I want to make a query that will display:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading