Does that question even make sense?
I’m trying to do a Query where it pulls 2 different values from a JOIN on the same table.
I have and “Order” where there are two values, “TakenBy” & “PackedBy” These are User_IDs from a table for Employees. Most of the time they will not be the same.
How do I seporate them in the query? I can get one of them fine, but I am unsure how to retreave both values.
Here what I have for getting one..
SELECT
O.Order_ID AS OID, Customer_ID AS CID, Emp.UserName AS UserName
FROM Orders O
LEFT JOIN Employees Emp ON Emp.User_ID = O.User_ID
WHERE O.Customer_ID =3
But, what about when I want the “PackedBy?” also how do I get that too?
[Employees Table]
[User_ID] [UserName]
[1] [Joe]
[2] [Bill]
[3] [Bobby]
[4] [Steve]
[Orders]
[Order_ID] [Customer_ID] [TakenBy] [PackedBy]
[10] [55] [3] [1]
[11] [66] [2] [4]
[12] [77] [3] [4]
[13] [88] [2] [1]
I want the Query to return somthing like
[OID] [CID] [TAKER] [PACKER]
[11] [66] [Bill] [Steve]
If you use different table aliases, you could join the same table more than once.
For example: