Setting the sort order

After adding one or more columns to the query, you may want to set the sort order of the query result set according to the contents of one or more of those columns.

To set the sort order:

  1. Determine which field or fields to use for ordering the data in the query result set.
    If using multiple sort fields, determine which field should be sorted on first, second, and so forth.

    In the following example, you may want to sort the data in order first by the date required by the customer.  Then for any date associated with two or more orders, you may want to sort the orders required on that date in order by order ID number.  Each order ID number should be unique, so the situation should not arise where two or more records exhibit the same order ID number, and further sorting on remaining fields is not necessary.

  2. For the primary sort field, click on the Sort Type cell and select the sort direction from the drop-down list.  This automatically enters "1" in the Sort Order cell for this field.

    Continuing from the above example, the primary sort field is "RequiredDate".
    To view the data in order beginning with the earliest required date, select Ascending.

  3. If using multiple fields, click on the Sort Type cell for the secondary sort field and select the sort order.  Repeat this step for all remaining sort fields.

    Continuing from the above example, the secondary sort field is "OrderID".
    To view the orders required on one day in order from the lowest order ID number to the highest, select Ascending.
    Since no ordering is needed on the "CustomerID" or "CompanyName", you can leave the Sort Type blank for these fields.

You can change the Sort Type and Sort Order for your query fields as needed.

To remove a sort order from one of the query fields, change the Sort Type from "Ascending" or "Descending" to "Unsorted".

 

More:

Adding criteria for the column

Adding GROUP BY and aggregate functions

Hiding a column from the query results

Setting an alias for the column

Adding columns to the query

Working with columns in a SELECT query