Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 28th, 2004, 12:31 PM
Authorized User
 
Join Date: Oct 2004
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
 
Old December 28th, 2004, 02:16 PM
Friend of Wrox
 
Join Date: Nov 2003
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
 
Old December 30th, 2004, 01:41 AM
Friend of Wrox
 
Join Date: Dec 2004
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.