给定以下数据库结构:
产品:
- id
- model
- manufacturerID
- subcontractorID
制造商ID 和分包商ID 是指同一张表,因为有些制造商也是分包商:
制造商:
- id
- name
现在,如果我想选择这两列,我该怎么做?
我尝试过这样的事情......
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
...但我只能得到两个列值之一。