If all you care about is the highest or lowest values produced by a query, you can use the Top Values list in the to display only these records. For example, you could use the Top Values list to display the ten largest or smallest orders in the Invoices table.
This lesson explains how you can use the Top Values list to display the top or in a query.
Click the qryTourSales query and then click the Design button.
Move to the next step and add the fields you want to see in your query.
Double-click the TourName field in the tblTours field list, and the Cost and Smoker fields in the tblCustomerTours field list.
You want to create a query that retrieves the five most expensive nonsmoking tours. First you need to add the nonsmoking criteria to the query.
Click the Criteria row in the Smoker column and type False.
Now you need to sort the field that you want to display the top or bottom values for. The Sort row works a little differently when you're using top or bottom values:
You want the query to display the top values in the Cost field, so...
In the Cost column, click the Sort box list arrow and select Descending.
Next you have to use the Top Values list to specify the number of top values you want to be displayed in your query results.
Click the Top Values list arrow on the toolbar and select 5, as shown in Figure 6-13.
This will display the five most expensive tickets. You're ready to run the query.
Click the Run button on the toolbar.
Access displays the results of the query, similar to Figure 6-14.
Click the View button on the toolbar to display the query in Design view.
You can also use the Top Values feature to display the top or bottom values from a calculation. Let's modify the query so that it calculates the total sales of nonsmoking tour sales.
If the Total row is not already displayed, click the Totals button on the toolbar.
The Total row appears. You need to specify which field you want to use to group the query, which field(s) you want to be calculated, and which fields are used to limit the number of records displayed in the query.
You want to group records using the TourName field, and since its Total row already displays Group By, you can leave it as it is. You will need to tweak the Total row for both the Cost and Smoker fields, however.
Click the Total row in the Cost column, click the list arrow, and select Sum from the list.
This will total the Cost field. The Smoker field is used as criteria to limit the records displayed to only nonsmokersit shouldn't be included in the query results. Move on to the next step to tell Access this.
Click the Total row in the Smokers column, click the list arrow, and select Where from the list.
One more change before we run the querythis time instead of displaying the top values for the Cost field we want to display its bottom values.
In the Cost column, click the Sort box list arrow and select Ascending.
This will summarize the five tours with the lowest sales (for nonsmokers). Let's see the results...
Click the Run button on the toolbar.
Access displays the results of the query, as shown in Figure 6-15.
Save the query as qryBottomTours and then close the query.
Table 6-6 explains what each of the options in the Top Values list does.
Table 6-6. The Top Values List
...to Display This
Click 5, 25, or 100 from the Top Values List
The top 5, 25, or 100 records
Type a number, such as 15 in the Top Values box
The top 15 (or specified number of) records
Click 5% or 25% from the Top Values List
The top 5 or 25 percent of records
Type a percentage, such as 20%, in the Top Values box
The top 20 percent (or specified percent) of records
Click All from the Top Values list
All of the records