title: MySql join statement with all rows in left table
body: <p>Assume I have three tables:</p>
  
  <pre><code>1. Fields
  ID
  NAME
  
  2. DATA
  ID
  f_id
  p_id
  data
  
  3. PROJECT
  ID
  </code></pre>
  
  <p>And I need to select all the rows from fields table every time with different data (depend on what project I need)
  So every time I will have all the rows of fields and if the project X does not have data for some field its will return empty row.</p>
  
  <p>I tried the following SQL statements:</p>
  
  <pre><code>SELECT * FROM field as f 
  left data as d on f.ID = d.f_id
  WHERE d.p_id = 'X'
  </code></pre>
  
  <p>This will return only the rows that project X has some data and will not return empty rows if there is no data.</p>
  
  <p>I also tried:</p>
  
  <pre><code>SELECT * FROM field as f 
  left join data as d on f.ID = d.f_id
  left join project as p on p.ID = d.p_id
  </code></pre>
  
  <p>This will returns all the rows from fields but will also return other projects data, and if Ill add Where statement its will not return empty rows if the project has no data.</p>
  
  <p>I also tried:</p>
  
  <pre><code>SELECT * FROM field as f 
  left join data as d on f.ID = d.f_id
  left join project as p on p.ID = d.p_id
  WHERE (p.ID == 'x' || p.ID is null) 
  </code></pre>
  
  <p>But this return field rows only if the rows are not using by other project, and if there is field that other project using it so I wont get this field. (not getting al rows from left table)</p>
  
  <p>How can I select all the rows from the left table (fields) anyway, also if the project has no data?</p>