title: how to select the latest data?
body: <p>I am using laravel 5, and I have a question for the SQL
  there is the table that record the function change of employee.</p>
  
  <p><a href="https://i.stack.imgur.com/gOIp3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gOIp3.png" alt="enter image description here"></a></p>
  
  <p>I just need the latest function so I wonder to use the "group by".
  but even I get the latest date, I could not get the corresponding data .</p>
  
  <p>The most close to what I want is like this </p>
  
  <pre><code> DB::table('function_history')
  -&gt;select(DB::raw('id_history,function_history.CUID,
                max(function_change_date)as time, id_function'))
     -&gt;orderBy('time','desc') -&gt;groupBy('CUID')-&gt;get();
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/qrIld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qrIld.png" alt="enter image description here"></a></p>
  
  <p>Thanks for your help</p>