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

List out what other servers you can use with ssrs?

99


What do you mean by table and field in sql?

652


What are the differences between clustered and non-clustered index?

621


Equi join and non equi join is possible with sql server?

575


why does a sql statement work correctly outside of a user-defined function, but incorrectly inside it? : Sql server administration

647






How can I track the changes or identify the latest insert-update-delete from a table?

626


what is the primary use of the model database? : Sql server administration

604


Can we take the full database backup in log shipping?

623


How to edit table in sql server 2017?

607


What is normalization? Describe its different types.

673


How can I check that whether automatic statistic update is enabled or not?

657


Explain system rowset functions?

654


How to use wildcard characters in like operations in ms sql server?

694


Which are the third-party tools used in sql server and why would you use them?

568


Explain go command in sql server?

637