Results 1 to 6 of 6
  1. #1
    Dachbo is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2015
    Posts
    42

    Select Query filtering duplicate records by criteria

    Hello,



    I have a table with employees. Some employees are listed several times in this table with different qualifications. I want a query that filters all the duplicate records by criteria, that every employee with his highest qualification is left.

    Click image for larger version. 

Name:	Access_Forum_Select Query Post.PNG 
Views:	13 
Size:	7.9 KB 
ID:	21080
    I don't know how the criteria should look like.

    Thank you

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Create an Aggregate (Totals) Query, where you Group By Employee and take the Max value of Qualification.
    You can do this using the Query Builder and using the Totals Query button (looks like a Sigma).

    The resulting SQL code of that query will look something like this:
    Code:
    SELECT Table_1.Employee, Max(Table_1.Qualification) AS MaxOfQualification
    FROM Table_1
    GROUP BY Table_1.Employee;

  3. #3
    Dachbo is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    42
    Thank you.

    How do I tell the query, which qualification is the lowest, the middle one and the highest?

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Well, I already showed you how to get the highest (Max). Just use Min to get the lowest.
    To get the middle is a little trickier, and may involve some VBA. Take a look here: https://msdn.microsoft.com/en-us/lib...ffice.12).aspx

  5. #5
    Dachbo is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    42
    I got access to find "the highest" value, but it's not the highest, it's just some random. The problem is the Qualifications are not named in some order. They are called like "A1", "A2", "RBB" or "OT". How do I tell Acces that "A1" < "A2" < "RBB" < "OT". Now Access might say "RBB" is the highest and not "OT"

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If they do not go in alphabetical order, you will need to create a "hierarchy" table (otherwise, how would it know your order?).
    You should have two columns in this table, the Qualification and its associated ranking number.
    Then you can link to this table, and use the ranking for your query to pick your highest/lowest rankings (much in the same way we should before, with the Aggregate Query).

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

Similar Threads

  1. Replies: 6
    Last Post: 06-24-2014, 10:09 PM
  2. Replies: 1
    Last Post: 12-20-2013, 05:14 PM
  3. Replies: 1
    Last Post: 08-31-2012, 01:56 PM
  4. Replies: 5
    Last Post: 08-02-2012, 09:44 AM
  5. Delete Duplicate Records Based on Criteria
    By chadd in forum Queries
    Replies: 2
    Last Post: 02-07-2012, 04:24 PM

Tags for this Thread

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