[英]Join two tables on different columns
I have two tables like below in mysql 我在mysql中有两个如下表
city 市
id from to
1 101 102
travel 旅行
id name
101 ABC
102 XYZ
I am trying to join table such that I will get ABC as source and XYZ as destination. 我正在尝试加入表格,这样我将以ABC作为来源,以XYZ作为目的地。 I tried multiple combinations but not getting expected result
我尝试了多种组合,但未获得预期的结果
Join the travel
table twice with different alias names 使用不同的别名将
travel
表连接两次
select c.id,
t1.name as city_from,
t2.name as city_to
from city c
join travel t1 on t1.id = c.`from`
join travel t2 on t2.id = c.`to`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.