SQLConfiguration SQLConfiguration


Creating Queries  «Prev 

Specifying a sort order

Specify Query Sort Order

  1. This datasheet is the result of a query. It seems to be sorted by date. However, you'd like to sort it by Company.
    Click the View button to see the query in Design view.
  2. To sort by Company you need to set a sort order in the Sort row for the Company field. Click the Sort row in the Company column to see the arrow for the drop-down list.
  3. Display the drop-down list by clicking the arrow and choose Ascending. Ascending sorts text data from the beginning of the alphabet to the end, date data from the earliest date to the latest, and number data from the smallest to the largest.
  4. Now that you have defined the sort order, have another look at the datasheet by clicking the View button on the toolbar.
  5. Although you can only see one company listed (except for the last record on the screen) the records do appear (and, in fact, are) to be sorted by company. However, the records for ABC Webworks, although they all appear at the top of the datasheet, seem to be in no particular order. You can specify a secondary sort field to put records with the same value in the primary sort field (in this case, all the records for ABC Webworks) in a particular order. Click the View button to return to Design view to further define the sort order for the query.
  6. Set Project ID as the secondary sort field. That way all the work for one project will appear together. Click the Sort row in the Project ID column to see the arrow for the drop-down list.
  7. Display the drop-down list and choose Ascending.
  8. Now view the datasheet again by clicking the View button.
  9. Here you see that now in addition to sorting by company the datasheet is also sorted by project ID. If you want, you can also sort by date--but remember that Access works from left to right when sorting, so it would sort first by Company, then by Project ID, then by Date because that is the order the fields appear in the query design.