Search code examples
phpsymfonydoctrine-ormdql

DQL - similar function to the mysql LAST


In mysql, there is a function last that returns the last found value. I would like to get the same with DQL in a symfony project. Is this somehow possible.

ie: I have 10 items in my table. With my where, I am getting 5 of them, but I would like to get the last of those 5:

$lastPaperQB = $this->createQueryBuilder( 'p' )
    ->select('LAST(p)')
    ->where("p.conference_id = :c AND p.section_id = :s")
    ->setParameter('c', $conference_id)
    ->setParameter('s', $section_id);

But the problem is that the LAST does not exist in DQL:

[Syntax Error] line 0, col 7: Error: Expected known function, got 'LAST' 

Solution

  • There's no such function in mysql. It's from ms access. You want to use order by together with limit. Without order by you are not guaranteed to get the same row from the 5 rows.