+ 1
Query for finding 2nd highest paid employee from EMP table?
4 ответов
+ 3
create table EMP (name string, salary int);
insert into EMP values ("Jim", 10000), ("Bob", 20000), ("Joe", 30000);
select * from EMP where salary < (select max(salary) from EMP) order by salary DESC LIMIT 1;
This selects Bob.
You can test this query in my SoloLearn app here:
https://code.sololearn.com/WUg6o4QaxPGU/?ref=app
+ 1
but it will give me record of employee having emp ID 2
0
I think this scenario will work:
if you have an id column . first select the salary column and sort it in descending order
then select the id column where it equals 2.
0
try this :
SELECT * FROM (SELECT * FROM emp ORDER BY salary DESC) WHERE ROWNUM= 2