Prepare for your Next Interview
This is a discussion on How to get 6th heghest salary? within the SQL Server forums, part of the Databases category; In SQL Server 2005, How to get 6th highest salary from a table? Regards, Prashanth Chenna....
| The Following 2 Users Say Thank You to chennaprashanth For This Useful Post: | ||
| Sponsored Links |
|
|||
|
Re: How to get 6th heghest salary?
There are already few posts for ur question. You can get your reply from here
http://http://www.geekinterview.com/...st-salary.html ---V V--- Vikas Vaidya |
|
|||
|
Re: How to get 6th heghest salary?
You can use the Query as fallowed
SELECT * FROM <TABLENAME> T1 WHERE n= (SELECT COUNT(DISTINCT <COLUMNNAME>) FROM <TABLENAME> T2 WHERE T1.<COLUMNNAME> <=T1.<COLUMNNAME>) where 'n' is the nth highest value for the <COLUMNNAME> in the <TABLENAME>. |
|
|||
|
select top 1 salary
from (select distinct top 6 salary from employee order by salary desc) a order by salary |
| The Following User Says Thank You to jrameshvjr For This Useful Post: | ||
|
|||
|
Re: How to get 6th heghest salary?
Hi jrameshvjr,
your query will give the only one record, if there are many number of employees holding the same salary then it won't be applicable.. |
|
|||
|
select top 1 emp_salary from (select top 6 emp_salary from tblemployee order by emp_salary desc) a order by emp_salary asc
|
| The Following User Says Thank You to Priyanka Sinha For This Useful Post: | ||
|
|||
|
Re: How to get 6th heghest salary?
select top(6) from tablename,but this will not applicable where there more number of employees drawing the same salary? it includes duplicate rows
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| nth highest salary | veluru13 | Oracle | 6 | 02-12-2008 10:47 AM |
| Structure of Salary | nehalshah | Companies | 2 | 12-07-2007 07:10 AM |
| employee name and salary from employee and salary table | Himu | SQL | 1 | 07-04-2007 05:34 AM |
| What is the value for MAX(SALARY) | Geek_Guest | SQL | 3 | 04-04-2007 04:01 AM |
| Assessing Salary | admin | Career Advice | 1 | 09-27-2006 05:23 AM |