Wednesday, June 1, 2011

find out the third highest salary in Sql?

create table Sal(salary int)

insert into Sal values(1000)
insert into Sal values(2000)
insert into Sal values(3000)
insert into Sal values(4000)
insert into Sal values(5000)

SELECT MIN(salary) FROM Sal WHERE
salary IN (SELECT  distinct TOP 3
salary FROM Sal ORDER BY salary DESC)

                        (or)

(SELECT MAX(salary)  FROM Sal
WHERE salary < (SELECT MAX(salary) FROM Sal
where salary < (SELECT MAX(salary) FROM Sal
where salary < (SELECT MAX(salary) FROM Sal))))

 

Output:

sql output

Share this post :

0 comments:

Post a Comment