Results 1 to 4 of 4

Thread: Access 2003 - Query To Retrieve the Latest Record

  1. #1
    Join Date
    Aug 2008
    Posts
    29

    Cool Access 2003 - Query To Retrieve the Latest Record

    Hi,
    Iam trying to retrieve the last record, based on date field (empanelDate) for each counselID from the table EmpanelmentTran.
    Code:
    SELECT EmpanelmentTran.counselID, Last(EmpanelmentTran.empanelDate) AS LastOfempanelDate
    FROM EmpanelmentTran
    GROUP BY EmpanelmentTran.counselID, EmpanelmentTran.empanelmentPurposeID;
    The above code retrieves all the records not just the last record for each counselID

    PS: I tried using MAX instead of LAST but with same result...

  2. #2
    Join Date
    Oct 2006
    Location
    Maitland NSW Australia
    Posts
    275
    You will display all records as you are grouping on counselID AND empanelmentPurposeID. As each counsel has one id but many PurposeIDs you will display the LAST date for EACH PurposeID. If you remove the PurposeID from the Group statement then you will display only one record for each counselID.
    Allan

  3. #3
    Join Date
    Apr 2011
    Posts
    1
    Mr. Allan,
    Pls advise me where this above code will set up?

    Awaiting yr reply.

    Thanks,
    Kishan

  4. #4
    Join Date
    Oct 2006
    Location
    Maitland NSW Australia
    Posts
    275
    Try this

    Code:
    SELECT EmpanelmentTran.counselID, Last(EmpanelmentTran.empanelDate) AS LastOfempanelDate
    FROM EmpanelmentTran
    GROUP BY EmpanelmentTran.counselID;
    Allan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •