I've got a table called Customers. And a table Users. (MySQL 5.3)
Customers:
customerID|customerName|accountManagerID|attendantID
123 |Google |456 |789
124 |Apple |457 |890
Users:
userID|userName
456 |Peter Norton
457 |Paul Allen
789 |Bill Gates
890 |Steve Jobs
I would like to be able to get the following result:
ID |Customer|Manager |Attendant
123|Google |Peter Norton|Bill Gates
I can get by using the following query:
SELECT customerID AS 'ID'
,customerName AS 'Customer'
,u1.accountManagerID AS 'Manager'
,u2.attendantID AS 'Attendant'
FROM Customers c
LEFT JOIN Users u1 ON (u1.customerID = c.customerID)
LEFT JOIN Users u2 ON (u2.customerID = c.customerID)
But I do think horrible do it this way, moreover, I consider 'little performatic'. Can someone point me to the right direction? Thanks!