2nd highest salary from the table [message #19140] |
Fri, 01 March 2002 19:10 |
ranni
Messages: 2 Registered: March 2002
|
Junior Member |
|
|
hi friends,
Can anyone help me with this question. Please!!!!
i want to make a query to find the second highest salary from a table in an Oracle database
thank you
|
|
|
Re: 2nd highest salary from the table [message #19141 is a reply to message #19140] |
Fri, 01 March 2002 19:53 |
Thomas
Messages: 67 Registered: September 1999
|
Member |
|
|
HI,
CONN SCOTT/TIGER@ORACLE
IN UR EMP TABLE
DO THIS QUERY IT WILL WORK.
U CAN CHANGE THE FIELD NAME AND TABLE AS U WISH
SELECT SAL FROM(SELECT SAL FROM(SELECT SAL FROM EMP ORDER BY SAL DESC )
WHERE ROWNUM < 3
ORDER BY SAL ASC)
WHERE ROWNUM < 2
THOMAS
|
|
|
Re: 2nd highest salary from the table [message #19152 is a reply to message #19140] |
Sun, 03 March 2002 22:30 |
jeya
Messages: 18 Registered: January 2001
|
Junior Member |
|
|
Selecting the nth highest salary:
select sal from emp e where &n=(select count(*) from emp where sal>=e.sal)
Selecting the 2nd highest salary:
select sal from emp e where 2=(select count(*) from emp where sal>=e.sal)
|
|
|