View Single Post
  #12 (permalink)  
Old 04-24-2008, 10:22 AM
Unregistered
 
Posts: n/a
Default ANY answer. Re: i want to get the third highest salary from a table?

Quote:
Originally Posted by lavanya View Post
I am not sure but it will definitely work just try once.


[sql]( select salary from <tablename> where sal <(select salary from <tablename> where sal <(select max(sal) from <tablename>))) [/sql]

This will give the third highest salary from a table.
And for the second highest salary just remove one phrase that is

[sql]select salary from <tablename> where salary<(select max(salary) from <tablename>)[/sql]


[sql]select salary from <tablename> where salary<(select max(salary) from <tablename> wont work for second highest salary.[/sql]

The correct query is
[sql]select max(salary) from <tablename> where salary<(select max(salary) from <tablename>[/sql]

to get the third highest salary :

[sql]( select max(salary) from <tablename> where sal <(select max(salary) from <tablename> where sal <(select max(sal) from <tablename>)))[/sql]
Reply With Quote