如何join
以下表格?或者这可能吗?
列origin
和destination
是fk。
**tbleroute**
ID ORIGIN DESTINATION
1 1 3
2 1 2
3 3 4
**tblelocation**
ID Name
1 Bus Station
2 Market
3 Bus Station 2
4 School
答案 0 :(得分:1)
对于明显的结果,您需要两个连接。这看起来像:
select r.*, lo.name as origin_name, ld.name as destination_name
from tblrouter r join
tbllocation lo
on r.origin = lo.id join
tbllocation ld
on r.destination = ld.id;
这种情况是from
子句中需要表别名来区分表。