 <p>I found a solution by thinking a bit different.</p> <p>This is eventually the function:</p> <pre><code>public function getPriceLines($pricelinematerial = 0, $year = 0, $week = 0) { if ($year === 0) { $year = (int)date('Y'); } if ($week === 0) { $week = (int)date('W'); } $query = $this-&gt;getEntityManager()-&gt;createQuery(' SELECT pgp FROM ACME\Bundle\PricelistBundle\Entity\PricelistMaterialPrice pgp WHERE pgp.pricelistmaterial = :pricelistmaterial AND pgp.year &lt;= :year AND pgp.week &lt;= :week ORDER BY pgp.year DESC, pgp.week DESC, pgp.id DESC ')-&gt;setParameters(array('pricelistmaterial' =&gt; $pricelistmaterial, 'week' =&gt; $week, 'year' =&gt; $year)); $query-&gt;setMaxResults(1); try { $result = $query-&gt;getSingleResult(); } catch (\Doctrine\ORM\NoResultException $e) { $result = null; } return $result; } </code></pre>