Nishanth Nair’s .Net Weblog

This blog contains intersting facts about C#, .NET, ASP.NET, Ajax and latest happenings in Microsoft Technologies

A common SQL Query

Posted by Nishanth Nair on April 11, 2008

This is a very simple SQL query for finding the 2nd highest salary from an employee table.

A very common question in .NET interviews. The query is pretty self explanatory.

select  top(1)[Name],Salary from Employee

where  salary  not in (select top (1) salary from employee order by salary desc)

– Change the top parameter to (nth highest salary – 1)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>