Finding Nth Highest Salary Query

SELECT max(sal) FROM  tbltemp WHERE sal NOT IN
(SELECT distinct top 2 sal FROM tbltemp ORDER BY sal desc)


for eg. for 3rd highest top will be 3-1 =2  (top 2) therefore top N-1


Or



SELECT TOP 1 sal 

FROM (

               SELECT DISTINCT TOP 2 sal
               FROM tbltemp
              ORDER BY sal DESC
              ) A
ORDER BY sal

Comments

Popular posts from this blog

How to get motherboard serial number, Processor ID, VolumeSerialNumber using C#?

Fiserv Interview Questions.

AngularJs - Simple Example