Results 1 to 3 of 3
  1. #1
    Mikey1987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Posts
    19

    Query: filter fields on max number

    Hello everyone,

    I'm sorry to ask sth that must be terribly easy for all of you, but I can't figure it out
    I have a table with two numberfields (let's call it NumbersToFilter and FilteringField)

    I want a query that shows me ALL NumbersToFilter data WHERE FilteringField is the highest

    Eg. if this is my table:
    NumberstoFilter / FilteringField
    999 / 50


    947 / 44
    920 / 50
    941 / 48

    I want my query to return 999 and 920 (filteringfield max = 50)

    I'm currently using an aggregate query, using group by NumberstoFilter and max FilteringField, but it returns all the fields (the maximum is simply on top )

    Any help?

    Thanks a lot,
    Mikey

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You want to use an Aggregate Query to return just the maximum values of the FilteringField (and nothing else).
    Then you can either create a new query based on your original table and this aggregate query, joining on the FilteringField field and returning the NumberstoFilter field,
    or you can use this aggregate query in a nested query to do the same thing in a single query.

    Here is what the SQL code structure of the nested query would look like:
    Code:
    SELECT NumberstoFilter
    FROM MyTable
    WHERE FilteringField in
    (SELECT Max(MyTable.FilteringField)
    FROM MyTable);

  3. #3
    Mikey1987 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Posts
    19
    Quote Originally Posted by JoeM View Post
    You want to use an Aggregate Query to return just the maximum values of the FilteringField (and nothing else).
    Then you can either create a new query based on your original table and this aggregate query, joining on the FilteringField field and returning the NumberstoFilter field,
    or you can use this aggregate query in a nested query to do the same thing in a single query.

    Here is what the SQL code structure of the nested query would look like:
    Code:
    SELECT NumberstoFilter
    FROM MyTable
    WHERE FilteringField in
    (SELECT Max(MyTable.FilteringField)
    FROM MyTable);
    Works like a charm
    u da best!

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

Similar Threads

  1. Replies: 4
    Last Post: 01-20-2015, 08:26 AM
  2. Replies: 11
    Last Post: 01-21-2014, 08:50 AM
  3. Replies: 1
    Last Post: 08-29-2013, 09:22 PM
  4. Replies: 10
    Last Post: 12-15-2010, 11:12 AM
  5. Replies: 2
    Last Post: 06-22-2010, 07:09 AM

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