我有两张桌子
**Location**
id int
name varchar
和
**User**
id int
name varchar
birthplace int
living_in int
其中birthplace和living_in是对位置id的引用
我想将输出显示为
Name Birthplace Living in
Joe LA NY
Bill Sac Orl
我的查询
select a.name, h.name as Birthplace, h.name as Living In
from User a
left join location h
on a.birthplace= h.id
left join location h
on a.living_in = h.id
没有给出所需的结果。任何帮助是极大的赞赏
使用适当的表别名,它变得更容易:
select u.name, b.name as Birthplace, l.name as LivingIn
from User u
left join location b
on u.birthplace= b.id
left join location l
on u.living_in = l.id