title: SQL join 2 tables to 1 table
body: <p>I am at the task of joining 3 tables:
  Task, Unit, and Building.</p>
  
  <p>The task table has a column for a unit and a column for a building.<br>
  Any single task is assigned to only a building OR a unit, never both. 
  Thus one column in every record is always null. There are 6100 records in the task table.</p>
  
  <p>when I use this JOIN: </p>
  
  <pre><code>select * from task t
  join building b on b.id = t.building_id;
  </code></pre>
  
  <p>I get 628 rows.  This is the correct total of building tasks.</p>
  
  <p>When I use this JOIN</p>
  
  <pre><code>select * from active_task at
  inner join unit_template ut on ut.id = at.unit_template_id
  </code></pre>
  
  <p>I get 5472 rows. This is the correct number of unit tasks.
  If I add them up 5472+628 =6100 this is the correct # of rows in the task table.</p>
  
  <p>When I run this Query:</p>
  
  <pre><code>select * from task t
  inner join unit ut on ut.id = t.unit_id
  inner join building bt on bt.id = t.building_id
  </code></pre>
  
  <p>I get zero rows.  I need my query to retrieve 6100 rows.
  Any help would be appreciated.</p>
  
  <p><img src="https://i.stack.imgur.com/ivP6c.jpg" alt="basic ER"></p>