title: How to match only last updated records in Doctrine?
body: <p>I am developing an application with Symfony2 and Doctrine, and have a table called <em>status</em> where I store the location and date books, such as:</p>
  
  <pre><code>ID  | Book        | Date       | Location
  ------------------------------------------------
  1   | Book_1      | 2011-08-29 | Home
  2   | Book_1      | 2011-08-30 | Office
  3   | Book_1      | 2011-09-02 | Friend's House
  4   | Book_2      | 2011-09-02 | Office
  5   | Book_2      | 2011-09-04 | Home
  </code></pre>
  
  <p>The status record with the most recent date represents the <strong>current</strong> (or last known) location of that book. In the above example, Book_1 is currently in "Friend's House" and Book_2 is in "Home".</p>
  
  <p>The following code gets <strong>any</strong> records that at some point had a location of "Home":</p>
  
  <pre><code>$em = $this-&gt;getEntityManager();
  $query = $em-&gt;createQuery('SELECT s FROM myBookTestBundle:Status s WHERE s.location=:x')-&gt;setParameter('x', 'Home');
  $status = $query-&gt;getResult();
  </code></pre>
  
  <p>Instead, I would like to select only those books whose <strong>current</strong> location matches "Home". In the above example, that would only be record ID = 5 (Book_2).</p>
  
  <p>Is there any way to do this easily with DQL?</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Thanks,<br />
  Ralph</p>