1

How is it possible to select the first row at the top of the selection without using native query option in JPQL/JPA?

@Query("select e from FOO e order by e.orderNumber desc")
Andronicus
  • 24,333
  • 17
  • 47
  • 82
Meysam Zarei
  • 394
  • 1
  • 11

1 Answers1

1

You might be able to use a max subquery here to restrict to the "first" row:

select e from FOO e where orderNumber = (select max(f.orderNumber) from FOO f);

This would be logically correct if orderNumber would always be guaranteed to be unique, in which case there would only be one max value.

Tim Biegeleisen
  • 451,927
  • 24
  • 239
  • 318