Answer the question
In order to leave comments, you need to log in
JOIN MySQL with 2 tables?
Good day, I ran into the following problem:
There is a request:
SELECT to_t.name, to_t.id FROM to_team_games to_t_g LEFT JOIN to_teams to_t on to_t_g.team_id_1 = to_t.id WHERE to_t_g = 1
SELECT to_t.name, to_t.id FROM to_team_games to_t_g LEFT JOIN to_teams to_t on to_t_g.team_id_1 = to_t.id LEFT JOIN to_teams to_t on to_t_g.team_id_2 = to_t.id WHERE to_t_g = 1
Answer the question
In order to leave comments, you need to log in
Here you need to set a unique alias for the third table, then it will work.
For example like this:
SELECT to_t.name, to_t.id, to_t2.name, to_t2.id
FROM to_team_games to_t_g
LEFT JOIN to_teams to_t on to_t_g.team_id_1 = to_t.id
LEFT JOIN to_teams to_t2 on to_t_g.team_id_2 = to_t2.id
WHERE to_t_g.id= 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question