find out the second highest salary?

Answer Posted / priyankur

@peter: your query is pretty cool but it wont work when
there are multiple salaries with same amount. I mean three
persons have same salary 24000, which is MAX sal in salary
table. In that case, below query will work.

select a.salary from employees a where 1 = (select count
(distinct b.salary) from employees b where
a.salary<b.salary)

Digit 1 is (n-1) where n is nth value. Here n is 2(Second
highest salary).

I would appreciate if anybody tried to break my above query
and explain how does this work.

Is This Answer Correct ?    7 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to enter a new row into a table interactively?

743


How can I combine multiple rows into a comma-delimited list in oracle?

791


How to start a specific oracle instance?

802


How to export several tables together?

779


ABOUT IDENTITY?

1751


Explain the use of grant option in exp command.

755


How to speed up webrick?

820


How to drop an existing table in oracle?

801


What is a cursor variable?

784


What is an oracle user account?

749


What is a cursor in oracle?

822


Can we convert a date to char in oracle and if so, what would be the syntax?

761


For a field in a repeating frame, can the source come from the column which does not exist in the data group which forms the base for the frame ?

1753


How to connect to a remote server?

772


How to use subqueries in the from clause in oracle?

815