Given is following database-structure:
Products:
- id
- model
- manufacturerID
- subcontractorID
manufacturerID and subcontractorID are referencing to one and the same table, because some manufacturers are also subcontractors:
Manufacturers:
- id
- name
Now, if I want to select both of these columns, how do I do that?
I tried something like this…
SELECT p.model, m.name AS Manufacturer, m.name AS Subcontractor
FROM Product AS p
LEFT JOIN Manufacturers AS m ON p.manufacturerID = m.id
LEFT JOIN m ON p.subcontractorID = m.id
… but I could only get one of both column-values.
Close – you need to join the Manufacturer table twice: