Results 1 to 5 of 5
  1. #1
    AquaLady42 is offline Novice
    Windows Vista Access 2003
    Join Date
    Jul 2011
    Posts
    2

    Pulling two most recent values (MAX)

    This seems like it should be simple, but I can't figure it out! (Sorry, I am a newbie!)



    I have a table called APPS that contains a number of fields:
    RECORDNUM = the customer number assigned
    CAPPNUM = the number assigned to an application
    PROCDATE = the date of an application (of which there may be many for an individual RECORDNUM)

    Basically the end result I want is to display a record number with the most recent application date (easy enough using the MAX function) but also the 2nd most recent application number.

    Example:
    12345 6/9/11 6/5/11

    I can't figure out for the life of me what to put to get the 2nd newest application date ... I have tried to copy a few examples I found, but they seem to be more complicated than I need.

    Any help? I APPRECIATE it a TON!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Depending on the final goal, this type of thing:

    http://support.microsoft.com/kb/153747/en-us

    or this type of thing, with code to limit to 2:

    http://allenbrowne.com/func-concat.html
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Expanding on Paul's suggestion and using this site

    http://allenbrowne.com/subquery-01.html
    try:
    Code:
    SELECT APPS.RecordNum, APPS.Cappnum, APPS.procdate
    FROM APPS
    WHERE (((APPS.procdate) In (SELECT TOP 2 procdate FROM APPS AS Dupe WHERE Dupe.RecordNum = APPS.RecordNUm)))
    ORDER BY APPS.RecordNum, APPS.procdate DESC;
    Alan

  4. #4
    AquaLady42 is offline Novice
    Windows Vista Access 2003
    Join Date
    Jul 2011
    Posts
    2

    not working for me

    Thanks for the suggestion but I am still having difficulty. I tried your query and it just sat there for hours without progressing to the "processing" stage. The table is not that large and I have never had anything take that long to even start running. Any ideas on why that may be?

    Thanks again for your help.

  5. #5
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Here is the db I created from the data you showed in the OP. Open it and compare the SQL statement and the QBE to what you have in your db. Mine works so I know the SQL statement is correct.

    Suggest you run a compact and repair before you do anything and see if that helps.

    Alan
    Last edited by alansidman; 07-22-2011 at 08:06 AM. Reason: C&R note

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Pulling values from a table
    By billdavidson in forum Programming
    Replies: 3
    Last Post: 05-16-2011, 11:44 AM
  2. Replies: 0
    Last Post: 03-28-2011, 05:06 PM
  3. Replies: 3
    Last Post: 12-21-2010, 11:52 AM
  4. pulling text values into FK number column
    By REBBROWN in forum Database Design
    Replies: 2
    Last Post: 08-30-2010, 05:04 PM
  5. Pulling most recent data from child table
    By davidv43 in forum Access
    Replies: 0
    Last Post: 02-07-2009, 11:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums