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
  • 25,419
  • 17
  • 47
  • 88
Meysam Zarei
  • 419
  • 2
  • 14

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
  • 502,043
  • 27
  • 286
  • 360