Tuesday, March 30, 2010

Get Nth Max Salary

Data Base used for the query processing :-

Table Name Employee
pkid Name Salary
1 apekshit 5000
2 gaurav 6000
3 sunil 7000
4 rajnish 6500
5 amit 8000

For finding Nth highest salary from a table without using TOP, GROUP BY AND ROW COUNT or any other SQL Keywords,

There are two options for this :-

1. OPTION

SELECT TOP 1 SALARY FROM (SELECT DISTINCT TOP N SALARY
FROM EMPLOYEE ORDER BY SALARY DESC)a
ORDER BY SALARY



2. OPTION

SELECT MAX(SALARY) FROM EMPLOYEE as E1
WHERE N=(SELECT COUNT(DISTINCT SALARY)
FROM EMPLOYEE E2 WHERE E1.SALARY<=E2.SALARY)

PASS THE NUMBER N VALUE...

1 comment:

Anonymous said...

Hie..

Can you please show me your Cricket Scorecard App?

I am BSc IT student. I am learning ASP.net on my own and I am developing a Cricket CMS system. :)

I am quite stuck at the Cricket Scorecard interface.

Please help me if possible :)

Reply at : dhaval.malte@yahoo.in

Thanks