Query for finding 2nd highest paid employee from EMP table? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Query for finding 2nd highest paid employee from EMP table?

2nd Dec 2016, 5:05 PM
Samrat Indra
Samrat Indra - avatar
4 Answers
+ 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
11th Jan 2017, 3:32 AM
Kirk Schafer
Kirk Schafer - avatar
+ 1
but it will give me record of employee having emp ID 2
2nd Dec 2016, 6:43 PM
Samrat Indra
Samrat Indra - avatar
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.
2nd Dec 2016, 6:37 PM
Bahhaāµ£
Bahhaāµ£ - avatar
0
try this : SELECT * FROM (SELECT * FROM emp ORDER BY salary DESC) WHERE ROWNUM= 2
2nd Dec 2016, 7:35 PM
Bahhaāµ£
Bahhaāµ£ - avatar