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

can an order by clause be used in a creation of a view?

695


explain different types of joins? : Sql server database administration

529


what is a self join? Explain it with an example? : Sql server database administration

499


What is a View ? Can we insert, Update and delete a view?

629


What are “phantom rows”?

1245






What is sql service broker?

588


How to trouble shoot if unable to connect SQL Server

1482


How to delete a login name in ms sql server?

535


What is fill factor and pad index?

542


What is the difference between varchar and varchar types?

568


How is table type constraint applied to a table?

551


What is an index. What are the types?

582


What is BCNF? How is it better than 2NF & 3NF?

597


Explain the xml support sql server extends?

622


If you want to send some data from access database to sql server database. What are different component of ssis will you use?

505