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

    MAX is still returning all records instead just MAX???

    Hi all,



    I am using the following query to find the maximum date for an employee's qualification:

    Code:
    SELECT tblCourseCatelog.CourseName, Max(tblEmployeeCourseExpiryDates.ExpiryDate) AS MaxOfExpiryDate, tblEmployeeCourseExpiryDates.ID, tblEmployeeCourseExpiryDates.EmpNO
    FROM tblCourseCatelog INNER JOIN tblEmployeeCourseExpiryDates ON tblCourseCatelog.CatelogID = tblEmployeeCourseExpiryDates.CatelogID
    GROUP BY tblCourseCatelog.CourseName, tblEmployeeCourseExpiryDates.ID, tblEmployeeCourseExpiryDates.EmpNO
    HAVING (((tblEmployeeCourseExpiryDates.EmpNO)=12345678));

    But 12345678 has two of the same course with different dates and the query is returning both records.

    What am I doing wrong? It works fine if I simply do:

    Code:
    SELECT tblEmployeeCourseExpiryDates.ExpiryDate, Max(tblEmployeeCourseExpiryDates.EmpNO) AS MaxOfEmpNO
    FROM tblEmployeeCourseExpiryDates
    GROUP BY tblEmployeeCourseExpiryDates.ExpiryDate
    HAVING (((Max(tblEmployeeCourseExpiryDates.EmpNO))=12345678));
    Thanks for the help!

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,821
    If you add too many fields to the situation, it can generate multiple Max values - one for each record that relates to one or more of the other fields. You would need to either create a query that finds the Max value in one field based on the minimum number of fields required, and use that as the filter for a second query or
    see subquery basics

    You will note that the example provided is based on returning records related to one meter (entity) and it may not work if more than one entity is involved.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    it is because you are grouping on tblEmployeeCourseExpiryDates.ID. Remove from your query

  4. #4
    scott0_1 is offline Advanced Beginner
    Windows Vista Access 2013 32bit
    Join Date
    Apr 2018
    Posts
    82
    Ugh. I hate using subqueries! Thanks for the help, I cheated and just deleted the last record from tblEmployeeCourseExpiryDates and inserted a new one. It's cheating, but it works!

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

Similar Threads

  1. Query not returning any records.
    By rebfein in forum Queries
    Replies: 3
    Last Post: 08-09-2016, 02:07 PM
  2. Not returning all records
    By cbende2 in forum Queries
    Replies: 2
    Last Post: 01-07-2015, 12:07 PM
  3. Query not returning records
    By Daryl2106 in forum Access
    Replies: 2
    Last Post: 02-28-2013, 07:58 PM
  4. Recordset not returning records
    By TinaCa in forum Programming
    Replies: 3
    Last Post: 08-03-2011, 09:26 AM
  5. Returning multiple records Isn't what I need
    By frobro390 in forum Queries
    Replies: 6
    Last Post: 09-21-2010, 06:24 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