title: Mysql, Multiple Left Join - 3 Tables
body: <p>I have some issues with multiple joins in MysQL
  I have 3 tables:</p>
  
  <ul>
  <li>cms_data_company </li>
  <li>cms_data_company_categories </li>
  <li>cms_datasrc_category</li>
  </ul>
  
  <p>Sample records from: <strong>cms_data_company</strong>:</p>
  
  <pre><code>+----+-----------+------------+
  | id | name      | address    |
  +----+-----------+------------+
  | 1  | Name1     | Samplestr1 |
  +----+-----------+------------+
  | 2  | Name2     | Samplestr2 |
  +----+-----------+------------+
  | 3  | Name3     | Samplestr3 |
  +----+-----------+------------+
  </code></pre>
  
  <p>Sample records from: <strong>cms_data_company_categories</strong> ( It contains Company_id field and category_id ) Point is that there is serveral records for one company_id )</p>
  
  <pre><code>+----+-----------+------------+
  | id | company_id| category_id|
  +----+-----------+------------+
  | 1  | 2         | 14         |
  +----+-----------+------------+
  | 2  | 2         | 11         |
  +----+-----------+------------+
  | 3  | 1         | 15         |
  +----+-----------+------------+
  </code></pre>
  
  <p>Sample records from: <strong>cms_datasrc_category</strong> ( Here is a issue that i need only that rows where:</p>
  
  <pre><code> datasrc = 1 AND parent = 0
  
  +----+-----------+------------+-----------+
  | id | datasrc   | parent     |name       |
  +----+-----------+------------+-----------+
  | 1  | 1         | 0          |category1  |
  +----+-----------+------------+-----------+
  | 2  | 2         | 0          |category2  |
  +----+-----------+------------+-----------+
  | 3  | 3         | 5          |category3  |
  +----+-----------+------------+-----------+
  </code></pre>
  
  <p>What i would like to recive is that:</p>
  
  <p><strong>All fields</strong> from cms_data_company and field <strong>name</strong> from cms_datasrc_company</p>
  
  <p>I need to join it as follows:</p>
  
  <ol>
  <li><strong>id</strong> from cms_data_company match with <strong>company_id</strong> from cms_data_company_categories </li>
  <li>Then matched <strong>category_id</strong> from
  cms_data_company_categories with <strong>ID</strong> from cms_datasrc_category (only these records where datasrc=0 and parent=0)</li>
  <li>Return name as new column with all field from cms_data_company</li>
  </ol>
  
  <p>I think I could make it messy, but my MySQL statement is as follows:</p>
  
  <pre><code>select * ,cms_datasrc_category.name_en
  from cms_data_company
  LEFT JOIN cms_data_company_categories.company_id
  ON cms_data_company.id = cms_data_company_categories.company_id 
  LEFT JOIN cms_datasrc_category
  ON cms_data_company_categories.category_id = cms_datasrc_category.id
  WHERE cms_datasrc_category.datasrc = 1 AND cms_datasrc_category.parent = 0
  </code></pre>
  
  <p>It seems It is working somehow but, there is only records from cms_data_company where query can find something. I would like to change my statemat to show NULLs when There is no matching fields.</p>
  
  <p>It is because WHERE applies to all Query ?</p>