Symfony2 & Doctrine2 get one result even if more exist inDB

175 Views Asked by At

Is there any equivalent for the following SQL code in Doctrine2?

    ORDER BY id DESC LIMIT 0,1
1

There are 1 best solutions below

0
On

Found it! The answer is

    ->setMaxResults(1)
    ->setFirstResult(0)

    ->getOneOrNullResult();