how to find top three highest salary in emp table in oracle(sql)
+2
A:
Something like the following should do it.
SELECT Name, Salary
FROM
(
SELECT Name, Salary
FROM emp
ORDER BY Salary desc
)
WHERE rownum <= 3
ORDER BY Salary ;
Martin Smith
2010-05-31 12:18:00
Simple answer to a stupid question.
amphetamachine
2010-05-31 12:19:46
Would homework be specific to a particular RDBMS or would it demand portable SQL?
Martin Smith
2010-05-31 12:24:14
Actually just seen the OP's last 3 questions and it does seem like homework day!
Martin Smith
2010-05-31 12:43:54
@dbemerlin: You are correct, this should be a comment. Now if you would kindly show me how I can add a comment to another's question with a reputation of less than 50, I'd be much obliged.
Christian Severin
2010-05-31 13:40:29
A:
SELECT *FROM ( SELECT *FROM emp ORDER BY Salary desc ) WHERE rownum <= 3 ORDER BY Salary ;
Aamir
2010-05-31 12:31:16
+3
A:
You can try.
SELECT * FROM
(
SELECT EMPLOYEE, LAST_NAME, SALARY,
RANK() OVER (ORDER BY SALARY DESC) EMPRANK
FROM emp
)
WHERE emprank <= 3;
This will give correct output even if there are two employees with same maximun salary
Bharat
2010-05-31 13:36:06