Selecting the Top Values with a Query in Access 2007

Microsoft Access, Tips & Tricks Add comments

Microsoft Access tutorial tweakWhen you put together an Access query, you add a table, select one or more fields from that table, and then specify your criteria: the expression that tells Access which records you want to see. When you then run the query, Access displays a dynaset (that is, a datasheet with the query results) that includes every record in the table that matches your criteria.

However, there are times when you don’t need to see every record that satisfies your crite­ria. For example, in a query of orders for last month, you might be interested in seeing only the biggest orders, whether in terms of the most units or the most dollars. Similarly, in a query of products, you might want to view only the most expensive items or the ones with the least inventory in stock.

For these situations, you can tell Access to restrict the dynaset to a specified number of records or to a percentage of the total:

  1. Set up your query table, fields, and criteria.
  2. For the field in which you want to see the top values, apply a Descending sort. (If you want to see the bottom values, instead, apply an Ascending sort.)
  3. In the Design tab, use the Top Values combo box (see Figure 1) to specify how much of the dynaset you want to return in the results:
    • Select a number or percentage value from the list.
    • Type a number or percentage in the text box.
    • Choose All to see every record.
  4. Choose Design, Run to see the query results.
Use the Top Values combo box to tell Access the number or percent­age of the top (or bottom) values you want to return
Figure 1 Use the Top Values combo box to tell Access the number or percent­age of the top (or bottom) values you want to return.

Technorati Tags: , ,

Popularity: 3% [?]

Related Post

  • Testing Action Queries (Carefully) in Access 2007
  • Selecting a Field Value from a List in Ms. Access 2007
  • Finding Duplicate Records with a Query in Access 2007
  • Creating a Simple Query with the Query Wizard in Access 2007
  • Selecting the “Home Cell” on All Worksheets in Excel 2007
  • Don't Find What You're Looking For? Please Try Here...

    Google
     

    2 Responses to “Selecting the Top Values with a Query in Access 2007”

    1. Kit Kerner Says:

      Hi,

      The “top value” is a great way to limit the results from a query. Now, I would like to go one step further by being able to dislplay all of one field (customer_ID) and limit the display of the second field (date_of_purchase). What this would do is show me all my customers and only the last (5) days their last purchase was made. I do not think that “top value” will work here.

      Thank you for even reading me!

      Kit Kerner
      Calabasas, CA

    2. Chet Rogers Says:

      Very helpful. Thanks

    Leave a Reply

    WP Theme & Icons by N.Design Studio
    Entries RSS Comments RSS Add to Technorati Favorites Log in