Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 28th, 2004, 12:31 PM
Authorized User
 
Join Date: Oct 2004
Location: Hyderabad, Andhra Pradesh, India.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to select 5th Max in a Table

Hi,

I have a question in writing the query.

In a table , two fields namely:
Sno Salary
with lot of records going on.

now, I have to select the 5th Max salary in the above table, how can do this.

Ramkumar


A.D.Ramkumar
__________________
Ramkumar A D
Reply With Quote
  #2 (permalink)  
Old December 28th, 2004, 02:16 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: Lehigh Acres, FL, USA.
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

The with ties will include any records that match the last item in the query

Code:
Select TOP 5 WITH TIES *
FROM Table A
Order by salary desc
and it also works with SELECT TOP 5 PERCENT WITH TIES

Jaime E. Maccou
Reply With Quote
  #3 (permalink)  
Old December 30th, 2004, 01:41 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

Sample Table Structure:
-----------------------

CREATE TABLE [dbo].[UserTable] (
    [RowNumber] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    [UserName] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [Age] [int] NULL
) ON [PRIMARY]
GO

Sample records:
---------------

07,Rajinikanth,56
01,Sachin,31
03,Vadivel,28
11,Sneha,25
12,Reema Sen,19

Query to find the 5th maximum age:
----------------------------------

Select * From
    (
    Select TOP 1 * From
        (
            Select TOP 5 * from UserTable order by age
        )
        as D1 ORDER BY age
    )
    as D2 ORDER BY age

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
select Max 2 rows for each ID veeruu SQL Language 1 January 31st, 2006 05:08 AM
Select two MAX record per each veeruu SQL Language 2 January 23rd, 2006 12:57 AM
Ani 1 noe how to retrieve record from select max() babymeizi Pro JSP 2 October 14th, 2004 05:11 PM
How to select Max hosefo81 MySQL 0 November 25th, 2003 10:27 PM
how to select Max hosefo81 PHP Databases 0 November 21st, 2003 12:58 AM



All times are GMT -4. The time now is 08:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.