Results 1 to 4 of 4
  1. #1
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107

    Exclamation If Duplicate and If another Duplicate then Pull the most recent data

    I have a set of client data that is not in a very good format, but have been tasked with trying to run several reports on the data by the end of today. I need to create a query that will sort the data by the employee number, check to see if there are duplicate course titles, and if there are duplicates, discard all but the most recent dates.



    EMP_ID COURSE_NAME DATE_COMPLETED
    123 Getting an A 1/25/2013
    123 Getting an A 7/08/2009
    456 Don't Fail 3/26/2003
    456 Make New Friends 1/16/2013
    456 Make New Friends 4/25/2009

    I want to create a query that will leave me data looking like this:

    EMP_ID COURSE_NAME DATE_COMPLETED
    123 Getting an A 1/25/2013
    456 Don't Fail 3/26/2003
    456 Make New Friends 1/16/2013

    I'm not sure how to even begin with this. Currently, we are pulling data from one data set, matching on the employee number, and grouping by the employee number:

    Code:
    SELECT [Report Data].EMPLOYEE_ID, [Report Data].COURSE_NAME, [Report Data].DATE_COMPLETED
    FROM [EE Numbers Report] INNER JOIN [Report Data] ON [EE Numbers Report].[EE Number] = [Report Data].EMPLOYEE_ID
    GROUP BY [Report Data].EMPLOYEE_ID, [Report Data].COURSE_NAME, [Report Data].DATE_COMPLETED;
    Any help with this would be greatly appreciated!

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You could try using the Max function on the date field to get the most recent. You will need to remove the date field from the GROUP BY clause

    SELECT [Report Data].EMPLOYEE_ID, [Report Data].COURSE_NAME, MAX([Report Data].DATE_COMPLETED) As MostRecent
    FROM [EE Numbers Report] INNER JOIN [Report Data] ON [EE Numbers Report].[EE Number] = [Report Data].EMPLOYEE_ID
    GROUP BY [Report Data].EMPLOYEE_ID, [Report Data].COURSE_NAME

  3. #3
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107
    Thank you for your help! This worked perfectly (and sorry for the long delay in marking this as complete!).

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome.

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

Similar Threads

  1. Duplicate data not showing in report
    By ashu.doc in forum Reports
    Replies: 2
    Last Post: 09-19-2012, 05:56 AM
  2. query showing duplicate data
    By dan-gauci in forum Queries
    Replies: 2
    Last Post: 10-20-2011, 02:58 PM
  3. Duplicate data fields
    By watergal82 in forum Access
    Replies: 1
    Last Post: 09-07-2010, 02:48 PM
  4. Duplicate data in report
    By JKrause in forum Reports
    Replies: 0
    Last Post: 03-23-2010, 10:07 AM
  5. Entering duplicate data in Form
    By cotri in forum Forms
    Replies: 1
    Last Post: 01-06-2010, 11:45 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