title: SQL join with last date
body: <p>Hello I trying to join type from table by 2 columns that gives multiply rows, so this doesn't work</p>
  
  <pre><code>SELECT t1_id, t1.Company  t1_some_field, t2_type 
  FROM t1 
  LEFT JOIN t2 ON t1.Company = t2.Company AND t1_id = t2_t1_id
  </code></pre>
  
  <p><strong>table t2</strong></p>
  
  <p>has multiply rows for <code>t2.Company + t2_t1_id</code> with different <code>t2_date</code> </p>
  
  <p>I need to join the <code>t2_type</code> with last <code>t2_date</code></p>
  
  <p>I do it like this</p>
  
  <pre><code>SELECT t1_id, t1.Company  t1_some_field, t2_type 
  FROM t1 
  LEFT JOIN t2
  ON t1.company = t2.company 
  AND t1_id = t2.t2_t1_id
  LEFT JOIN
      (SELECT MAX(t2_date) AS Last_Date, company, t2_t1_id
          FROM t2
          GROUP BY company, t2_t1_id) last_t2
  ON t1.company = last_t2.company 
  AND t1_id = last_t2.t2_t1_id
  
  WHERE t2_date = Last_Date;
  </code></pre>
  
  <p>looks like this works, but I think should be an easier way. </p>