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 21st, 2006, 01:13 AM
Authorized User
 
Join Date: Jan 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select two MAX record per each

Hi!

I would be very happy if anybody could help me in the following.

table contains the following fields,
    ConsultantID
    ConsultantType
    StartDate
    ExpDate
    UpdatedDate
    UpdatedBy
    UpdatedInfo
The tables allows same IDs(more than One) with diff. data with new UpdatedDate
I need a query to display .. MAX Two Reords based on Updated date for all IDs. this is my basic one.
and after getting the two records for each consultantID,
I need to display the secondMax record only if the defference between
the secondMax record (ExpDate) and FirstMAx record (Startdate) is less than 25.

Im working on this qurey from last 3 days ...
Plz.. help me to get the solution...

Thanks & Regards,
Veeru.



 
Old January 21st, 2006, 05:50 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

show some sample data and your desired resutls. This will help us help you

Jim

 
Old January 23rd, 2006, 12:57 AM
Authorized User
 
Join Date: Jan 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, This is My sample Data ...
Plz. help me....
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 records for each CID.
And display Second Record if diff. between
Second Exp.Date and Current Date is 25.

Thanks & Regards,
Veeru.






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
How to select 5th Max in a Table ramk_1978 SQL Language 2 December 30th, 2004 01:41 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.