-1

It's quite simple problem but I am begginer and i have problems with it.

I have 2 tables in database

  1. matches id, team1id, team2id, score, date
  2. teams id, name

If I want to select team1 name, team2 name, score and date what command should I use?

gmuru
  • 1
  • Does this answer your question? [How to get the values of two foreign key columns when they correspond to the same key?](https://stackoverflow.com/questions/72277175/how-to-get-the-values-of-two-foreign-key-columns-when-they-correspond-to-the-sam) – Ross Presser Jun 06 '22 at 15:06

1 Answers1

1

You should use a double "join" on teams table. I wrote a sheet of how you should use it :

select 
     matches.id,
     teamA.name,
     teamB.name,
     score,
     date 
from matches
inner join teams teamA
on teamA.id = matches.team1id
inner join teams teamB 
on teamB.id = matches.team2id
Issac411
  • 54
  • 4
  • If it helps you, note my response as answer. Next time, try to do some research by your own, there are tons of tutorial about that case. – Issac411 Jun 06 '22 at 13:27