'select sal from emp order by sal desc limit 1,1;

select sal from emp order by sal desc limit 1,1;

SQL command not properly ended GIVES ERROR

I wan´t to get the employee with the NTH highest salary in each department.

I´m using SQL.

sql


Solution 1:[1]

You can use the ANSI syntax offset ... fetch ...:

select sal from emp order by sal desc offset 1 rows fetch next 1 rows only;

Solution 2:[2]

I hope you find it useful Link

but you will need group by if you need it by section

  select 
    department,
    max(sal) 
  from emp 
  group by department

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zakaria
Solution 2 O'tkir Xo'jayev