Wednesday, June 1, 2011

find out the second 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 2
salary FROM Sal ORDER BY salary DESC)

0 comments:

Post a Comment