我正在try 学习如何将一个表中的多个列连接到另一个表中的单个列.
This is my table structure in its simplest form:
团队
id | team_name |
1 | teamA |
2 | teamB |
3 | teamC |
4 | teamD |
贸易
id | team_1 (FK to 团队.id) | team_2 (FK to 团队.id) |
1 | 1 | 2 |
2 | 3 | 4 |
This is my current SQL which joins 贸易.team_1 to 团队.id:
SELECT 团队.team_name AS team1, 团队.team_name AS team2, 贸易.team_1, 贸易.team_2
FROM 团队
JOIN 贸易 ON (贸易.team_1 = 团队.id);
My question is, how do I create a second join that also joins 贸易.team_2 to 贸易.id?
This would mean both 贸易.team_1 AND 贸易.team_2 would be joined to 贸易.id
The results I want to get back would be:个
team1 | team2 | team_1 | team_2 |
teamA | teamB | 1 | 2 |
teamC | teamD | 3 | 4 |