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 January 24th, 2006, 12:57 AM
Authorized User
 
Join Date: Jan 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default select Max 2 rows for each ID

Hi,
I need a query to display .. MAX Two Rows for all IDs.
The tables allows same IDs(more than One) with diff. data with new UpdatedDate

 This is My sample Data ...
CID CType StartDate ExpDate UpdatedDate
--- ---- -(MM/DD/YYYY)- ----------- ------------
 1 B1 01/01/2004 03/03/2004 01/02/2004
 1 OPT 03/06/2004 03/03/2005 03/10/2004
 1 H1 03/01/2005 01/03/2008 03/04/2005
 2 B1 10/01/2004 01/09/2005 10/04/2004
 2 OPT 01/06/2005 01/03/2006 03/07/2006
 2 H1 01/01/2006 01/03/2009 01/04/2006

I need a select query to display the result as follows..

 1 H1 03/01/2005 01/03/2008 03/04/2005
 2 OPT 10/06/2005 01/03/2006 10/07/2006
 2 H1 01/01/2006 01/03/2009 01/04/2006

i.e. 2 MAX Updated rows for each CID.
And display Second Row if diff. between
Second Exp.Date and Current Date is 25.

Plz. Help Me....

Thanks & Regards,
Veeru.


 
Old January 31st, 2006, 05:08 AM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nalla Send a message via Yahoo to nalla
Default


Hi veeruu,
Based on what you want MAX 3 rows? You said "MAX Two Rows for all IDs" but what do you mean by MAX?


nalaka hewage





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Max function to return single rows. beerOne SQL Language 1 November 6th, 2008 04:52 PM
Crystal reports max rows in detail section lokilewis Crystal Reports 2 October 6th, 2005 02:47 PM
Problem with displaying ID when finding max or min marcin2k Access VBA 1 October 3rd, 2005 07:42 AM
Urgent please help to find Max ID and add 1 to it nhatrang71 Access 5 June 28th, 2004 10:24 PM
How to get max value within same id jackps SQL Server 2000 1 January 20th, 2004 07:26 AM





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