[ Team LiB ] Previous Section Next Section

Ordering Query Results

When you run a new query, the query output appears in no particular order. Generally, however, you want to order query output. You can do this by using the Sort row of the query design grid.

To order the results of a query, follow these steps:

  1. In Design view, click within the query design grid in the Sort cell of the column you want to sort (see Figure 10.6).

    Figure 10.6. Changing the order of query results.

    graphics/10fig06.jpg

  2. Use the drop-down combo box to select an ascending or descending sort. Ascending or Descending appears in the sort cell for the field, as appropriate.

Sorting by More Than One Field

You might often want to sort query output by more than one field. The columns you want to sort must be placed in order, from left to right, on the query design grid, with the column you want to act as the primary sort on the far left and the secondary, tertiary, and any additional sorts following to the right. If you want the columns to appear in a different order in the query output, you must move them manually in Datasheet view after you run the query.

Task: Ordering Query Results

graphics/todo_icon.gif

To sort query results in ascending order by the ContactTitle field, follow these steps:

  1. In Design view, click the Sort row of the query design grid for the ContactTitle field.

  2. From the Sort drop-down combo box, select Ascending.

  3. Run the query and view the results. The records should now be ordered based on the ContactTitle field.

  4. If you want to return to Design view of the query, click View on the toolbar.

  5. Sort the query output by the Country field and, within individual country groupings, by the ContactTitle field. Because sorting always occurs from left to right, you must place the Country field before the ContactTitle field. Select the Country field from the query design grid by clicking the thin gray button above the Country column.

  6. After you have selected the Country field, move the mouse back to the thin gray button and click and drag to the left of the ContactTitle field. A thick gray line should appear to the left of the ContactTitle field.

  7. Release the mouse button.

  8. Change the sort order of the Country field to Ascending.

  9. Run the query. The records should be in order by country and, within the country grouping, by contact title.

    [ Team LiB ] Previous Section Next Section