title: Find last records in table by FK
body: <p>My table looks like:</p>
  
  <pre><code>id
  caseid
  status
  </code></pre>
  
  <p>Example data in the table:</p>
  
  <pre><code>1   10    open
  2   10    published
  3   10    reopened
  4   11    open
  5   11    contact
  6   11    response
  7   11    published
  </code></pre>
  
  <p>I need to get all <code>caseid</code>s where the last status was <code>published</code>.</p>
  
  <p>So in the above example only <code>11</code> would be retrieved (because the caseid 10 was reopenend later).</p>
  
  <p>What would the query look like?</p>
  
  <p>PS</p>
  
  <p>I'm using PDO with prepared statements.</p>