Home > Back-end >  Second Highest Salary using JPA method
Second Highest Salary using JPA method

Time:12-25

I recently faced an interview question to find 2nd highest salary from MySQL table.

I gave the query,

select Distinct salary from Employee order by salary desc limit 1 offset 2.

But he asked me to write the same with JPA in build method queries..

I was able to guess like findBySalaryGreaterThan..

Not able to get the correct answer..

How to write JPA in build method query for second highest salary..

CodePudding user response:

Have you got this basic query in JPA?

So just add pagination to that query, set the page size to 1 and get the second page.

  • Related