Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
| 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
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


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

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

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

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

Sample records:

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

Reply With Quote

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.