I will be concrete. I have the following tables: [All connected together]
Clients | Products | Others | Employees ID | ID | ID | ID desc | desc | idemployeeBy | name idproduct | | idemployeeTo | idother |
I want to start selecting the ID, plus product description.
SELECT clients.ID, products.desc
So far, so good. Now I need to select the employeesBy and employeesTo 'name', acording to the fields of others table that has a "connection" with clients table.
So I thought of doing this:
SELECT clients.ID, P.description, E.name AS 'Open by', E1.name AS 'Assigned To' FROM clients INNER JOIN others ON others.id = clients.id LEFT JOIN products AS P ON P.ID = clients.idprodut LEFT JOIN employees AS E ON E.ID = others.idemployeeBy LEFT JOIN employees AS E1 ON E1.ID = others.idemployeeTo GROUP BY others .id, clients.ID, P.description, E.name, E1.name ORDER BY clients.ID DESC
I don't know if I'm not explaining properly..?
Am I doing this correctly? I can't test in SQL Query right now, only tomorrow.
Thank you guys.
This post has been edited by Keylogger: 07 May 2013 - 11:39 AM