Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting unexpected results from a join query
    primarykey
    data
    text
    <p>So I have the following <code>query</code> for <code>mysql</code> db</p> <pre><code>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' </code></pre> <p>and it returns exactly what I want. I can also query like this</p> <pre><code>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' &lt;!-- this line is different --&gt; </code></pre> <p>Again it returns exactly what I want. Yet if I run this query</p> <pre><code>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' </code></pre> <p>I get 0 results. Now for the present, this is working, but as this database grows there will be multiple components with the same name in the same company. So I need to add an extra unique identifier, which is project_id. </p> <p>Why isn't the third query returning what the first two are? How do I fix it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload