Results 1 to 4 of 4
  1. #1
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47

    Question How to get the latest date for each person achieved level 1

    Hi All,

    I have a table as following
    RecDate name level points
    20140601 A 1 123
    20140601 B 2 22
    20140603 A 1 51
    20140604 A 3 58
    20140604 C 1 15



    The result of the query i m expecting is the following

    RecDate name level points
    20140603 A 1 51
    20140604 C 1 15

    the goal is to get the latest date for each person who achieved level 1, those at other levels will be left out, i thought it could be a inner join query but i just can't get it right, please help

  2. #2
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Am assuming, you have the RecDate field set as Date Type & have different names for Name & Level Fields.
    One way could perhaps be :
    Code:
    SELECT 
        tblRecords.NameF, 
        Max(tblRecords.Recdate) AS MaxOfRecdate, 
        tblRecords.Level, 
        Last(tblRecords.Points) AS LastOfPoints
    FROM 
        tblRecords
    GROUP BY 
        tblRecords.NameF, tblRecords.Level
    HAVING 
        (((tblRecords.Level)=1));

    The second way could perhaps be :
    Save below as Query2
    Code:
    SELECT 
        tblRecords.NameF, 
        Max(tblRecords.Recdate) AS MaxOfRecdate
    FROM 
        tblRecords
    WHERE 
        (((tblRecords.Level)=1))
    GROUP BY 
        tblRecords.NameF;

    Run this query :
    Code:
    SELECT 
        Query2.NameF, 
        Query2.MaxOfRecdate, 
        tblRecords.Recdate, 
        tblRecords.NameF, 
        tblRecords.Level, 
        tblRecords.Points
    FROM 
        tblRecords 
        INNER JOIN 
        Query2 
        ON 
        (tblRecords.NameF = Query2.NameF) 
        AND 
        (tblRecords.Recdate = Query2.MaxOfRecdate);

    Note : Pls pay attention to my signature.


    Thanks

  3. #3
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47
    Thanks recyan,

    I tried both ways, they work fine and i actually combined the 2 queries for the 2nd one

    Code:
    SELECT tblRecords.NameF, tblRecords.Recdate, tblRecords.Level, tblRecords.Points
    FROM tblRecords INNER JOIN
     (SELECT tblRecords.NameF, Max(tblRecords.Recdate) AS MaxOfRecdate 
    FROM tblRecords WHERE (((tblRecords.Level)=1)) GROUP BY tblRecords.NameF)  AS Query2 
    ON (tblRecords.NameF=Query2.NameF) AND (tblRecords.Recdate=Query2.MaxOfRecdate);
    It's great that i got help that quick!!

  4. #4
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Glad you got things working.

    Thanks.

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

Similar Threads

  1. Getting only latest date info into a report
    By fshrago in forum Reports
    Replies: 1
    Last Post: 10-18-2013, 02:29 AM
  2. Value of latest date
    By v!ctor in forum Queries
    Replies: 3
    Last Post: 02-27-2013, 03:48 PM
  3. How do you get the latest date?
    By radicrains in forum Queries
    Replies: 6
    Last Post: 10-27-2010, 08:59 PM
  4. Query to find latest date
    By Lockrin in forum Access
    Replies: 2
    Last Post: 12-16-2009, 10:00 AM
  5. Latest Date Records
    By Rick West in forum Queries
    Replies: 1
    Last Post: 09-25-2009, 11:16 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