table1
id firstname
-------------
1 Elon
2 Steve
table2
id profession
-------------
1 Entrepreneur
2 Engineer
table3
firstname profession
-------------
1 2
2 1
需要结果:
firstname profession
-------------
Elon Engineer
Steve Entrepreneur
如何从一个MySQL查询中的不同表中进行选择? 如何从一个MySQL查询中的不同表中进行选择?
答案 0 :(得分:1)
此声明应该为您提供所需的结果。
select t1.firstname, t2.profession from table1 t1 join table3 t3 on t1.id=t3.firstname join table2 t2 on t3.profession = t2.profession
答案 1 :(得分:0)
你可以这样做:
SELECT t1.firstname, t2.profession
FROM table1 as t1
LEFT JOIN table3 as t3 ON t1.id = t3.firstname
LEFT JOIN table2 as t2 on t2.id = t3.profession
这个有效,经过测试