我有两张桌子:
personal
____________
| id | name |
| 15 | Mike |
| 23 | Rich |
| 35 | Hugo |
和
events
___________________________
| id | driver | translator |
| 22 | 15 | 23 |
| 23 | 35 | 35 |
有没有办法加入这两个表来获得像
这样的东西events
___________________________________
| id | driverName | translatorName |
| 22 | Mike | Rich |
| 23 | Hugo | Hugo |
THX
答案 0 :(得分:1)
你可以试试这个
SELECT
e.id
,p1.name driverName
,p2.name translatorName
FROM `events` e
JOIN `personal` p1
ON p1.id=e.driver
JOIN `personal` p2
ON p2.id=e.translator
答案 1 :(得分:1)
这将有效
select e.id, (select name from Personal where id = e.driver) as DiverName,
p.name as TranslatorName
from Personal p
inner join [events] e on p.id = e.translator