Thursday 20 October 2011

How to find nth highest salary

Question : normally this question asked that write the query for nth highest sal ?
Answer: u use any one of them
1.    select distinct a.salary from Salary a where 5=( select count(distinct b.salary) from Salary b where     a.salary<=b.salary)
------------------------------------------------------
2. Select top 1 salary from (
  
Select Distinct top n salary
    from
employee
    order
by  salary desc) a
    order by
salary

---------------------------------------
3.SELECT distinct salary FROM
(
    SELECT DENSE_RANK() OVER (ORDER BY salary DESC) AS rank, salary
    FROM property_R
) T2
WHERE rank=1 

2 comments:

  1. hello Rohit i didn't get what you have done. Can you please do it with the help of asp .net as i am an asp .net programmer.

    ReplyDelete
  2. Hi vivek above are three simple SQL Server query.
    U can make a store procdure and call this in your ASP .net page .
    if any confusion then let me know

    ReplyDelete