please tell me the query to get details of the employee
having the second largest salary

Answer Posted / rathi

If we had a table named Employee which had a column named
Salary and we had to find the second highest Salary in the
Employee table, the query for the same would be:

SELECT TOP 1 Salary FROM (SELECT TOP 2 Salary FROM Employee
ORDER BY Salary DESC) AS E ORDER BY Salary ASC

The subquery or the inner query would return the top 2 rows
in descending Salary order which would be:
5000
4000
The outer query would then select the top 1 row from the
subquery results in ascending Salary order which would be:
4000

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is default port number for sql server 2000?

753


What is an example of a foreign key?

695


What are the basic functions for master, msdb, model, tempdb databases?

784


How can we migrate from SQL server to SQL Azure?

106


what are cursors? : Sql server database administration

719






Can sql server 2016 run on windows 7?

678


What are partitioned views and distributed partitioned views?

798


Why use identity in sql server?

723


How to get the definition of a view out of the sql server?

702


Why do we use trigger?

710


What is raid, and how it can influence database performance?

760


What is transaction server auto commit?

743


query processing

1921


How to view the error log for any specific instance? : sql server database administration

771


what is a live lock? : Sql server database administration

630