所以我有query
以下mysql
db
SELECT CFM.display_name, CFM.field_type, CFM.option_value
FROM company_mast
LEFT JOIN component_mast ON company_mast.id = component_mast.company_id
LEFT JOIN CustomField_mast CFM ON CFM.Company_ID = Component_mast.Company_ID
AND CFM.Component_ID = component_Mast.Component_ID
WHERE component_mast.component_name = 'Assets'
AND component_mast.project_id = '1'
它返回的正是我想要的。我也可以这样查询
SELECT CFM.display_name, CFM.field_type, CFM.option_value
FROM company_mast
LEFT JOIN component_mast ON company_mast.id = component_mast.company_id
LEFT JOIN CustomField_mast CFM ON CFM.Company_ID = Component_mast.Company_ID
AND CFM.Component_ID = component_Mast.Component_ID
WHERE component_mast.component_name = 'Assets'
AND company_mast.company_name = 'Company' <!-- this line is different -->
它再次返回正是我想要的。然而,如果我运行这个查询
SELECT CFM.display_name, CFM.field_type, CFM.option_value
FROM company_mast
LEFT JOIN component_mast ON company_mast.id = component_mast.company_id
LEFT JOIN CustomField_mast CFM ON CFM.Company_ID = Component_mast.Company_ID
AND CFM.Component_ID = component_Mast.Component_ID
WHERE component_mast.component_name = 'Assets'
AND component_mast.project_id = '1'
AND company_mast.company_name = 'Company'
我得到 0 个结果。目前,这是可行的,但是随着该数据库的增长,同一公司中将有多个具有相同名称的组件。所以我需要添加一个额外的唯一标识符,即project_id。
为什么第三个查询不返回前两个?我如何解决它?