title: Limit one row per unique column value selecting by max column value
body: <p>I'm trying to select the most recent <code>WorkOrder</code> for each <code>Customer</code>. I've used <code>ORDER BY</code> and <code>GROUP BY</code>, but the result returned is not the newest <code>WorkOrder</code>.</p>
  
  <p><strong>Table Structure:</strong></p>
  
  <pre><code>WorkOrder
      id
      customer_id
      create_date
      ...
  </code></pre>
  
  <p><strong>Sample Data:</strong></p>
  
  <pre><code>WorkOrder.id    WorkOrder.customer_id   WorkOrder.create_date   ...
  1               1                       2012-01-01 12:00:00
  2               1                       2016-06-29 12:00:00
  3               2                       2015-05-05 12:00:00
  </code></pre>
  
  <p><strong>Desired Result:</strong></p>
  
  <pre><code>WorkOrder.id    WorkOrder.customer_id   WorkOrder.create_date   ...
  2               1                       2016-06-29 12:00:00
  3               2                       2015-05-05 12:00:00
  </code></pre>
  
  <p><strong>Current Code:</strong></p>
  
  <pre><code>$query = DB::table('WorkOrder')
      -&gt;orderBy('WorkOrder.create_date', 'desc')
      -&gt;groupBy('WorkOrder.customer_id');
  
  // select * from `WorkOrder` group by `WorkOrder`.`customer_id` order by `WorkOrder`.`create_date` desc
  </code></pre>
  
  <p><strong>Current Result:</strong></p>
  
  <pre><code>WorkOrder.id    WorkOrder.customer_id   WorkOrder.create_date   ...
  1               1                       2012-01-01 12:00:00
  3               2                       2015-05-05 12:00:00
  </code></pre>