Results 1 to 4 of 4
  1. #1
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    82

    Using LAST but still getting all records??


    Hello all,

    I have the following query where ID is an Autonumber:

    Code:
    SELECT Last(tblActingTMP.ID) AS LastOfID, tblActingTMP.EmpName, tblActingTMP.SubstantiveCC, tblActingTMP.SubstantivePN, tblActingTMP.ActingForName, tblActingTMP.PositionNumber, tblActingTMP.ActingCC, tblActingTMP.StartDate, tblActingTMP.EndDate, tblActingTMP.Excluded
    FROM tblActingTMP
    GROUP BY tblActingTMP.EmpName, tblActingTMP.SubstantiveCC, tblActingTMP.SubstantivePN, tblActingTMP.ActingForName, tblActingTMP.PositionNumber, tblActingTMP.ActingCC, tblActingTMP.StartDate, tblActingTMP.EndDate, tblActingTMP.Excluded;

    The query should only return the last record if I'm not mistake, but it is returning all records in the table. What am I doing wrong here? I've also tried MAX.

    Thanks,

    Scott

  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,521
    It will return all the unique combinations of the fields in the GROUP BY clause, with the LAST ID value. If you want the last record:

    SELECT TOP 1 *
    FROM tblActingTMP
    ORDER BY ID DESC
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    82
    Quote Originally Posted by pbaldy View Post
    It will return all the unique combinations of the fields in the GROUP BY clause, with the LAST ID value. If you want the last record:

    SELECT TOP 1 *
    FROM tblActingTMP
    ORDER BY ID DESC
    That got it! Thanks! I've not seen the TOP function before.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 12-09-2016, 08:58 AM
  2. Replies: 1
    Last Post: 04-06-2016, 09:26 AM
  3. Replies: 4
    Last Post: 03-29-2014, 01:29 AM
  4. Replies: 1
    Last Post: 01-24-2013, 05:50 PM
  5. Access 2007 - Creating New Records Based on Existing Records
    By GeorgeAugustinePhillips in forum Forms
    Replies: 9
    Last Post: 10-05-2011, 05:58 PM

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