hrishi hrishi - 1 year ago 64
MySQL Question

Join two tables on different columns

I have two tables like below in mysql


id from to

1 101 102


id name

101 ABC

102 XYZ

I am trying to join table such that I will get ABC as source and XYZ as destination. I tried multiple combinations but not getting expected result

Answer Source

Join the travel table twice with different alias names

select, as city_from, as city_to
from city c
join travel t1 on = c.`from`
join travel t2 on = c.`to`
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download