两个不同值的左连接

cyvaqqii  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(302)

塔布市

id_city   city
  1       Paris
  2       Texas
  3       Toquio

选项卡\u控件

id_control origin  destination
 1             1           3

对于前面的表,我需要从tab\u控件获取数据,并从tab\u city获取相应的城市。
如果只是起源很简单:

SELECT origin.tco, city.tci
FROM tab_control tco
LEFT JOIN tab_city tci ON tco.origin = tci.id_city

返回

origin = 1
city = Paris

但是,我需要

origin = 1
city = Paris
destination = 3
city_destination?? = Toquio
mzmfm0qo

mzmfm0qo1#

你需要再来一杯 JOIN 目的地

SELECT tco.origin, tci.city, tco.destination, d.city
FROM tab_control tco
LEFT JOIN tab_city tci ON tco.origin = tci.id_city
LEFT JOIN tab_city d ON tco.destination = d.id_city

相关问题