Jun 21st, 2009 | 3 Comments

Since I am looking for a job change and this is the question I’m being asked in all of my interviews, I am sharing this with everyone hoping this will help you guys.

The most common type of question is find out the 5th highest value, find out the 2nd highest value, and so on.

The solution for this question goes like this, I am going to fetch 5th highest salary for an employee.

Select top 1 FirstName, Salary From Employees Where Salary Not In (Select Distinct Top 4 Salary From Employees order by Salary desc) order by Salary desc

Enjoy and have fun :)

Written by Ajay Matharu

June 21st, 2009 at 1:51 pm

  • http://salviashish.wordpress.com Ashish Salvi

    Hey AJ,

    Its nice query, it has helped me a lot in some of my interviews :) Thanks for sharing it with us.

    Thanks,
    Ashish Salvi
    http://www.twitter.com/ashishsalvi

  • Mrunali

    Thank You So much.. it helped me a lot in my interview… thanks Again..

  • http://www.ajaymatharu.com Ajay Matharu

    Cool, did you crack the interview?