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
List out what other servers you can use with ssrs?
What do you mean by table and field in sql?
What are the differences between clustered and non-clustered index?
Equi join and non equi join is possible with sql server?
why does a sql statement work correctly outside of a user-defined function, but incorrectly inside it? : Sql server administration
How can I track the changes or identify the latest insert-update-delete from a table?
what is the primary use of the model database? : Sql server administration
Can we take the full database backup in log shipping?
How to edit table in sql server 2017?
What is normalization? Describe its different types.
How can I check that whether automatic statistic update is enabled or not?
Explain system rowset functions?
How to use wildcard characters in like operations in ms sql server?
Which are the third-party tools used in sql server and why would you use them?
Explain go command in sql server?