我有两张桌子
**Location**
id int
name varchar
和
**User**
id int
name varchar
birthplace int
living_in int
出生地和 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
未提供所需结果。非常感谢任何帮助
答案 0 :(得分:3)
使用适当的表别名,它变得更容易:
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