C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




query to get fifth highest amount


Posted Date: 07 Sep 2008      Total Responses: 6

Posted By: Shivashankar Chincholi       Member Level: Gold     Points: 1



I need a query to get fifth highest amount in salary field.




Responses

Author: Ritesh N. Jain    07 Sep 2008Member Level: GoldRating:     Points: 2

many time this same question have beed asked on this forum,wonerding why dont you use search Functionality.
anyway as far as your query is concern this will work



SELECT Top 1 Salary
FROM (SELECT TOP 5 Salary FROM Table Order by Salary Desc)
Order by Salary Asc



Author: Bunty    07 Sep 2008Member Level: DiamondRating:     Points: 2

Hi,

Select TOP 1 sal
From (Select TOP 5 sal from <table-name>
ORDER BY sal desc)
ORDER BY sal.

Regards
S.S.Bajoria


Thanks & Regards
S.S.Bajoria



Author: Muralee Krishnan.K    08 Sep 2008Member Level: GoldRating:     Points: 2

Select Max(Salary) from table_Name Where Salary Not IN (Select TOP 5 From Table_Name order by salary desc)

Regrads
Muralee

Muralee Krishnan.K



Author: UltimateRengan    08 Sep 2008Member Level: DiamondRating:     Points: 2

hi,

Select top 1 salary from Table_Name where salary in
(Select top 1 salary from Table_Name order by salary desc)
order by salary desc

Ex:-
select top 1 salary from emp where salary in
(select top 5 Salary from emp order by salary desc)
order by salary desc

I hope this may help u

UltimateRengan
nathan.rengan@gmail.com
Trichy-Rider Group



Author: Shivashankar Chincholi    08 Sep 2008Member Level: GoldRating:     Points: 3

Hi,

I have tried all above queries everything is giving wrong answers.

This is the right query to get 5th highst Salary.

select Top 1 <Column_Name> from(select distinct top 5 <Column_Name> from <Table_Name>
order by <Column_Name> desc) <Temp_Table_Name> order by <Column_Name>

You can give any name instead of <Temp_Table_Name>.


Regards
Shivu..



Author: Ravi Kiran Nedunuri    30 Sep 2008Member Level: GoldRating:     Points: 3

hi you try the following subquery like below

select max(sal)from emp where sal<(select max(sal) from emp where sal<(select max(sal) from emp where sal< (select max(sal) from emp where sal<(select max(sal) from emp))))

Regards
N.RaviKiran



Post Reply
You must Sign In to post a response.
Next : Function
Previous : sql server normalization
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use