Home > Software engineering >  select sal from emp order by sal desc limit 1,1;
select sal from emp order by sal desc limit 1,1;

Time:03-02

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.

CodePudding user response:

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

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

CodePudding user response:

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
  •  Tags:  
  • sql
  • Related