Mysql 如何从两个SQL表中进行选择

Mysql 如何从两个SQL表中进行选择,mysql,Mysql,我试图使用外键链接我的SQL表,然后用select语句调用数据。。我的桌子是空的 team table team_id name match table match_id team1_id team2_id round 我想从match表中选择match_id,其中team1的名字是“alpha”,team2的名字是“bravo”,round是1。我想我需要一个连接,但在如何实现它的问题上有点纠结 试试这个: SELECT mt.*, tbl1.name as team1_name,tbl

我试图使用外键链接我的SQL表,然后用select语句调用数据。。我的桌子是空的

team table
team_id 
name

match table
match_id
team1_id
team2_id
round
我想从match表中选择match_id,其中team1的名字是“alpha”,team2的名字是“bravo”,round是1。我想我需要一个连接,但在如何实现它的问题上有点纠结

试试这个:

SELECT mt.*, tbl1.name as team1_name,tbl2.name as team2_name  from match_table as mt 
JOIN teamtable as tbl1 ON mt.team_id=tbl1.team1_id 
JOIN teamtable as tbl2 ON mt.team_id=tbl2.team12_id
WHERE mt.team1_id='alpha' AND mt.team2_id='bravo' AND mt.round=1;

它没有经过测试。测试它。

好的,谢谢,我做了一些修改,然后就可以使用了,我还修改了我的表match:)@JS60:-不客气!很高兴我能伸出援助之手。快乐编码!
Try this:

select m.* 
from team  t inner join on match m on t.team_id = m.team1_id and t.team2_id 
where t.name in ('alpha','bravo') and m.round = 1