Geeks Talk

Prepare for your Next Interview




How to get 6th heghest salary?

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....


Go Back   Geeks Talk > Databases > SQL Server

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-18-2008
chennaprashanth's Avatar
Contributing Member
 
Join Date: Mar 2008
Location: Pune
Posts: 30
Thanks: 0
Thanked 9 Times in 7 Posts
chennaprashanth is on a distinguished road
Question How to get 6th heghest salary?

In SQL Server 2005, How to get 6th highest salary from a table?


Regards,
Prashanth Chenna.
Reply With Quote
The Following 2 Users Say Thank You to chennaprashanth For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 03-19-2008
Contributing Member
 
Join Date: Jun 2007
Location: Delhi, India
Posts: 50
Thanks: 0
Thanked 22 Times in 18 Posts
vikasvaidya is on a distinguished road
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
Reply With Quote
  #3 (permalink)  
Old 08-11-2008
Junior Member
 
Join Date: Apr 2008
Location: Hyderabad
Posts: 28
Thanks: 1
Thanked 4 Times in 2 Posts
nageshkota is on a distinguished road
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>.
Reply With Quote
  #4 (permalink)  
Old 08-27-2008
Junior Member
 
Join Date: Aug 2008
Location: Tamilnadu
Posts: 2
Thanks: 1
Thanked 1 Time in 1 Post
jrameshvjr is on a distinguished road
Thumbs up Re: How to get 6th heghest salary?

select top 1 salary
from (select distinct top 6 salary from employee order by salary desc) a
order by salary
Reply With Quote
The Following User Says Thank You to jrameshvjr For This Useful Post:
  #5 (permalink)  
Old 08-29-2008
Junior Member
 
Join Date: Apr 2008
Location: Hyderabad
Posts: 28
Thanks: 1
Thanked 4 Times in 2 Posts
nageshkota is on a distinguished road
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..
Reply With Quote
  #6 (permalink)  
Old 09-09-2008
Junior Member
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Amitaqa is on a distinguished road
Re: How to get 6th heghest salary?

select * from <tablename>emp where salary not in (select distinct top n-1 salary from <tablename>emp order by salary desc)

n=number of highest salary
Reply With Quote
  #7 (permalink)  
Old 3 Weeks Ago
Junior Member
 
Join Date: Mar 2008
Location: Dehli
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Priyanka Sinha is on a distinguished road
Smile Re: How to get 6th heghest salary?

select top 1 emp_salary from (select top 6 emp_salary from tblemployee order by emp_salary desc) a order by emp_salary asc
Reply With Quote
The Following User Says Thank You to Priyanka Sinha For This Useful Post:
  #8 (permalink)  
Old 1 Week Ago
Junior Member
 
Join Date: Nov 2008
Location: hyderabad
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
manasachowdary is on a distinguished road
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
Reply With Quote
Reply

  Geeks Talk > Databases > SQL Server


Thread Tools
Display Modes


Similar Threads

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


All times are GMT -4. The time now is 09:18 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved