title: Group by date and take the last one
body: <p>This is my table :</p>
  
  <p><img src="https://i.stack.imgur.com/SDbpF.png" alt="Database"></p>
  
  <p>What I'm trying to do, is to take the last disponibility of a user, by caserne. Example, I should have this result :</p>
  
  <pre><code>id    id_user    id_caserne    id_dispo    created_at
  31    21         12            1           2019-10-24 01:21:46
  33    21         13            1           2019-10-23 20:17:21
  </code></pre>
  
  <p>I've tried this sql, but it does not seems to work all the times :</p>
  
  <pre><code>SELECT * FROM 
      ( SELECT id, id_dispo, id_user, id_caserne, MAX(created_at) 
      FROM disponibilites GROUP BY id_user, id_caserne, id_dispo 
      ORDER BY created_at desc ) AS sub 
  GROUP BY id_user, id_caserne
  </code></pre>
  
  <p>What am I doing wrong ?</p>