How to find out second height salary from table in sql server?

Total Post:96

Points:676

 1608  View(s)
Ratings:
Rate this:
Hi Expert!

I'm new in database. My problem is that, how to find second height salary from table in sql server. I'm getting height salary as following...

CREATE DATABASE DEMO

USE DEMO

CREATE TABLE tblEmployee
(
EmpID INT PRIMARY KEY,
Salary MONEY
)

INSERT INTO tblEmployee(EmpID,Salary) VALUES (100,10000)
INSERT INTO tblEmployee(EmpID,Salary) VALUES (102,20000)
INSERT INTO tblEmployee(EmpID,Salary) VALUES (103,30000)
INSERT INTO tblEmployee(EmpID,Salary) VALUES (104,15000)
INSERT INTO tblEmployee(EmpID,Salary) VALUES (105,35000)

SELECT MAX(Salary) AS 'Height Salary ' FROM tblEmployee

It return '35000.00' that's max salary, but how to get second max salary '30000'!

Please help me!

Thanks in advance!
  1. Re: How to find out second height salary from table in sql server?

    Hi Ben!


    You can try as following

    select MAX(Salary) from tblEmployee where Salary not in (select MAX(Salary) from tblEmployee)

    OR

    select MAX(Salary) from tblEmployee where Salary < (select MAX(Salary) from tblEmployee)

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.