pvaju896
pvaju896

Reputation: 1417

How to find the Second largest value from a table.?

One table with EmpSalary in Employee Table. I need to find the second largest Salary what is paid by the company.?

How to find the Second largest value(Salary) from a table.?

Upvotes: 3

Views: 6957

Answers (3)

pvaju896
pvaju896

Reputation: 1417

select top(1) prodMrp from Product where not prodMrp = (select top(1) prodMrp from Product order by prodMrp DESC ) order by prodMrp DESC

Upvotes: -1

Anurag
Anurag

Reputation: 348

Try this: this should give the second largest salary:

SELECT MAX(EmpSalary) FROM employee WHERE EmpSalary < (SELECT MAX(EmpSalary) FROM employee);

Upvotes: 3

anivas
anivas

Reputation: 6547

;WITH CTE AS ( SELECT ROW_NUMBER() OVER (ORDER BY SortColumn DESC) AS RowNumber, * 
               FROM YourTable)
SELECT * FROM CTE WHERE RowNumber = 2

Upvotes: 7

Related Questions