title: SQL: Joining table A and table B when rows may be missing in TABLE B
body: <p>I'm trying to join data from two table A, and B on a timestamp. I ideally want every row of tableA that meet the unitCode and time constraints, and if there is an associated row in tableB then join it, otherwise assume the coloumns from table B are attached but are null or empty. </p>
  
  <p><em>Assume TableA looks something like this:</em> </p>
  
  <p><strong>id | timestamp | itemA1 | itemA2 | itemA3</strong></p>
  
  <p><em>and TableB looks somthing like this:</em> </p>
  
  <p><strong>id | timestamp | itemB1 | itemB2</strong></p>
  
  <p>so data might look like this: </p>
  
  <ul>
  <li>timestamp | itemA1 | itemA2 | itemA3 | itemB1 | itemB2 </li> 
  <li>[datetime]| 10     | 11     | 40     | 26     | 12 </li>
  <li>[datetime]| 10     | 11     | 40     | 26     | 12 </li>
  <li>[datetime]| 10     | 11     | 40     | null   | null </li>
  <li>[datetime]| 10     | 11     | 40     | 26     | 12 </li>
  <li>[datetime]| 10     | 11     | 40     | null   | null </li>
  </ul>
  
  <p>Currently I'm using this:</p>
  
  <pre>
  SELECT * FROM tableA AS a 
  JOIN (SELECT * FROM tableB) AS b
  ON (a.timestamp = b.timestamp)
  WHERE b.unitCode = 'CODE' AND b.timestamp BETWEEN 'STARTDATETIME' AND 'ENDDATETIME' ORDER BY b.timestamp DESC`
  </pre>
  
  <p>but it only makes rows out of the instances where there is a corresponding tableB for a given tableA.</p>