我有下表:
Technician
Tech_ID,First_Name,Last_Name
RT_QUEUE_Delta
Tech_ID, RT_Complete` (references a `Tech_ID` in `Technician`).
我需要从
RT_Queue_Delta
其中的RT_Completed = ??
行中获取数据,但是在我的输出中,我需要具有与First_Name
和Last_nam
相关的Tech_id
和RT_Completed
e。我可以匹配一个,但我不知道如何匹配两个。我试过了:
select RTTech.First_Name as RT_First_Name,
RTTech.Last_Name as RT_Last_Name
from Technician as RTTech
Join RT_Queue_Delta as RT
on RT.RT_Completed = RTTech.Tech_ID
最佳答案
您可以多次加入Technician
表:
select d.tech_id, t.first_name, t.last_name,
d.rt_completed as completed_id,
t2.first_name as completed_first_name,
t2.last_name as completed_last_name
from RT_QUEUE_Delta d
join Technician t on d.tech_id = t.tech_id
join Technician t2 on d.RT_Completed = t2.tech_id
关于mysql - 同一张表上的多个联接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30203810/