title: Select the latest inserted row of a group of registers in Symfony2?
body: <p>I have a table called <strong>note</strong> that is related to <strong>budget</strong> by <code>budget_id</code> column.</p>
  
  <p>I need to select only the last inserted row for each different foreign key. I have so far this query:</p>
  
  <pre><code>public function findLastNotes()
  {
      return $this
              -&gt;createQueryBuilder('n')
              -&gt;orderBy('n.id', 'DESC'
              -&gt;groupBy('n.budget')
              -&gt;getQuery()
              -&gt;getResult();
  }
  </code></pre>
  
  <p>But it returns the <strong>first</strong> register for each foreing key.</p>