how to find nth highest salary

Answer Posted / sysdomain

'top' will fetch only top most : ie top 5 means it will
fetch first 5 rec. After fetching rec only 'order by' is
done ie sorting is done after fetching. therefore using
'top' and 'order by' alone wont get max or min value. for
that we have to use 'distinct' before 'top' (which will sort
the records before fetching).

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

Is This Answer Correct ?    7 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the advantages of user-defined functions over stored procedures in sql server?

671


Can you explain what are the restrictions applicable while creating views? : SQL Server Architecture

664


What is normalization according to you and explain its different levels?

688


What is the synonym of join?

688


What is difference between joins and subqueries?

740


How to download and install sql server 2005 books online?

764


How to enforce security in sql server? : sql server security

807


What are the differences between left join and inner join in sql server?

773


What does top operator do?

750


What are views in ms sql server?

790


Can sql servers linked to other servers?

733


Is truncate a dml command?

688


Explain what you mean by 3 tier architecture.

805


What is check constraint in sql server?

718


Recommend an approach to ensuring that all changes in the remote databases synchronize with the SQL Azure database?

122