C
C
CryptoPython2018-10-23 22:19:39
SQL
CryptoPython, 2018-10-23 22:19:39

How to get data from the database from the table, if 1 (column with primary key) and the same column are referenced by 2 other columns (2 foreign keys and 1 primary?

In general, the essence of the task is as follows: there is a table where the names of the teams are written, and their number is timid (has a primary key).
There is also a table where there are 2 columns the home team and the away team, these columns contain the same numbers as in the teamid column, you need to make a connection from the home team and the away team to the teamid and so that after the id of the X team
and the G teams , you could find out their name, the question is: is it possible to do this and how to do it, if possible? I tried to just make foreign keys to the column, but then when I create a query in the editor, it does not display anything, empty lines.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
V Sh., 2018-10-24
@KryptoPython

SELECT hv.homeId, h.Name, hv.visitorId, v.Name
FROM home_visitor hv, teamInfo h, teamInfo v
WHERE hv.homeId = h.Id AND hv.visitorId = v.Id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question