title: Get the max column value for each unique ID
body: <p>I have two tables, a <code>customers</code> and <code>orders</code> table.</p>
  
  <p>The <code>customers</code> table contains a unique <code>ID</code> for each customer. It contains 1141 entries.</p>
  
  <p>The <code>orders</code> table contains many entries with a <code>customerID</code> and a <code>date</code>.</p>
  
  <p>I am trying to query my database and return a list of customers and the <code>max(date)</code> from the orders list. </p>
  
  <pre><code>SELECT *
  FROM customers
  INNER JOIN
  (
      SELECT CustomerID, max(date) as date
      FROM orders
      GROUP BY CustomerID
  ) Sub1
  ON customers.id = Sub1.CustomerID
  INNER JOIN orders
  ON orders.CustomerID = Sub1.CustomerID
  AND orders.date = Sub1.Date
  </code></pre>
  
  <p>However this query is returning 1726 rows instead of 1141 rows. Where is this getting extra from?</p>