Swapnil Nikam :
I have a attach table having 7 records in each department. I need to make a query that finds the 5th highest salary for each department.
GMB :
Use row_number()
(if you are running MySQL, this requires version 8.0):
select *
from (
select
t.*,
row_number() over(partition by department order by salary desc) rn
from mytable t
) t
where rn = 5