title: limiting query results in a table join
body: <p>I need select the employee id's from the last delivery unless the status = OTD from the hta table.  Then I need to get all remaining employee id's from the employee table and display those results. Unfortunately employees with a status of otd are also in the employee table.  Can I write a query that will return these results?  Or do I have to do it differently?  If so can you guide me.</p>
  
  <pre><code>   SELECT h.employee_id
          , MAX(h.delivery_date)
          , e.employee_first
          , h.status 
       FROM TABLE_HTA h 
      RIGHT
       JOIN TABLE_EMPLOYEES e 
         ON h.employee_id = e.employee_id 
      WHERE h.status &lt;&gt; "OTD" 
      GROUP 
         BY h.employee_id 
      ORDER 
         BY MAX(h.delivery_date) ASC
  
  Table_hta&lt;br&gt;
  order_id |  employee_id | status | delivery_date |&lt;br&gt;
         1 |    23        |  OTD   | 1/1/15 3:45pm&lt;br&gt;
         2 |     24       |DELIVER | 1/1/15 3:50pm&lt;br&gt;
         3 |     25       |DELIVER | 1/1/15 3:51pm&lt;br&gt;
  &lt;br&gt;
  Table_employees&lt;br&gt;
  employee_id | employee_first |&lt;br&gt;
      23        Bob&lt;br&gt;
      24        James&lt;br&gt;
      25        Henry&lt;br&gt;
      26        Sally&lt;br&gt;
  
  Results&lt;br&gt;
  employee_id |  employee_first | delivery_date&lt;br&gt;
         26 |Sally&lt;br&gt;
         24 |James |1/1/15 3:50pm&lt;br&gt;
         25 |James |1/1/15 3:51pm&lt;br&gt;
  </code></pre>
  
  <p>Sally was included because she did not have the status OTD.  Bob was excluded because he had the status OTD.</p>