Take different names from the same column using two different ID's from other table

Shelly Miron :

I'v got this tables in mySQL database:

Orders:

Order_ID   ID_employee   ID_Manager
-----------------------------------

123            345           678
234            678           333
146            222           679

personal_info

Person_ID      name    
----------------------

345            Mickey        
333            Mike          
222            Jack   

I want to get from each table the Order_ID and the names of the employee and his manager. How can i do that? i tried to write a query using INNER JOIN, but failed to understand how to take it from both tables, i also tried to do a sub-query, with no success.

forpas :

You must join orders to 2 copies of personal_info, the 1st to get the employee's name and the 2nd to get the manager's name:

select o.order_id, p1.name employee, p2.name manager
from orders o
inner join personal_info p1 on p1.person_id = o.id_employee
inner join personal_info p2 on p2.person_id = o.id_manager

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=293288&siteId=1