sql 将 name_id 替换为另一个 table 的名字

sql substitute name_id with names from another table

我有三个 table:

match:
id, team1_id, team2_id, tournament_id
333, 4772, 4708, 4508

teams:
id, name
4772, Wolves
4708, Bolton

tour:
id, name
4508, Premier League

我想将此作为来自比赛的查询来执行 - 其中 team1_id、team2_id、tournament_id 被 table 队和巡回赛的值所取代。

example: "select * from match where id=333" 应导致:

333, Wolves, Bolton, Premier League

还有tables有几万行..

尝试使用查询

select m.id, t1.name, t2.name,t3.name 
from match m inner join teams t1 on m.team1_id=t1.id 
inner join teams t2 on m.team2_id=t2.id 
inner join m.tournament_id=t3.id

试试这个:

select * from match m 
inner join teams t on m.team1_id=t.id 
inner join teams s on m.team2_id=s.id 
inner join tour o on o.id = m.tournament_id 
where m.id=333