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
What is database isolation in sql server? : sql server database administration
How to provide values to user defined function parameters?
You notice that the transaction log on one of your databases is over 4gb the size of the data file is 2mb what could cause this situation, and how can you fix it?
What extended events?
What is a constant or literal in ms sql server?
Mention the different types of triggers?
Ms sql server index?
What is single-user mode and what are the steps you should follow to start sql server in single-user mode?
Explain what is row_number function?
According to you what goes into making the best database administrator? : sql server database administration
What are the requirements for sql server 2016?
What do you mean by an execution plan? How would you view it?
What is the difference between online clustering and Offline clustering?
How to find the version of sql server? : sql server database administration
How to insert data into an existing table?