Order Operation--Sort Query Results
Use the Order operation to specify the order in which your retrieved data displays.
Choosing Order on the Retrieve frame temporarily clears all qualification specifications from the Retrieve frame form so that you can enter order qualifications. Any previously entered sort‑order specifications displays.
The frame menu now displays the following operations:
Blank
Clears any specifications that have been entered.
Cancel
Restores the previous ordering specifications, if any, and returns to the previous Retrieve frame.
Help, End
Standard operations.
Sort Sequence and Sort Priority
You control the order in which data displays in your window by specifying the sort order. Sort order is governed by sort keys. Sort keys are data columns (fields) that have been given a sort priority number. For example, if a field called Name is the sort key, QBF presents all the data rows in alphabetic order by Name.
If you do not use the Order operation to specify a sort order, QBF displays the data according to how it is stored in the table. How data is stored in the table depends on the table's storage structure.
By default, QBF sorts columns in ascending order.
You can specify the sort order in master and detail tables, with or without table fields, for any query target.
For example, Lastname might be the first field listed on the form and Zip the fifth. But if you specify that you want zip‑codes to be the primary sort key, and last names the second sort key, your data is displayed by zip‑code in numeric order with the last names within each zip‑code arranged alphabetically.
To set the ordering sequence for a field
1. Click Order on the Retrieve frame.
2. Put the cursor in a column (field) you want to sort on.
3. Type a number from 1 to 1024, which is the sort priority number.
QBF sorts the field with the lowest number first. The first sort is called the primary sort. If you want the field displayed in descending order, follow the sort priority number by d (or D). For ascending order, you can enter a (or A) or no letter, because ascending order is the default.
4. If you want a secondary sort, repeat steps 2 and 3 in the secondary sort field. Make sure that the number you enter in the secondary field is higher than the number entered in the primary field. If you want additional sorts, continue this process until all the fields you want to sort on have been assigned a sort priority.
5. When you are finished, click End to return to the original menu for the Retrieve frame and remove the sort order specifications.
6. Click Go to execute the query.
7. If you choose Order again, the previous sort priority numbers and sort sequence letters display in the fields. To change them, type new values. Use the Blank operation to erase all sort specifications and begin with a blank form.
You can assign a sort sequence to any and all fields and table fields on the form.
The Order operation treats sort sequence numbers as relative. If you assign sequence numbers 1, 3, and 80, Order interprets them as follows:
1 primary
3 secondary
80 tertiary
The following figure shows a JoinDef of the Projects and Tasks tables. The primary sort column is Dept. The secondary sort column is Budget. Because d is specified for Budget, the highest figure is displayed first. The third sort column (specified as 5) is Due Date, and the fourth (specified as 10) is Project.
When specifying sort order, the default is ascending order (A before B, 1 before 2). If you type d for descending order, the Order operation sorts text fields in reverse order (Z before Y, 9 before 8). If desired, you can use a colon (:) to separate the priority number from the sort direction.
For example, specifying either 2d or 2:d in the Budget field makes Budget the secondary sort key and instructs QBF to display the results in descending order according to Budget (highest budget first, lowest budget last).
Keep in mind that QBF sorts numbers in numeric fields differently than numbers in character fields. Numbers in numeric fields are sorted by value (1, 2, 3, 10, 11, 12, 101, 112, 121,...). When numbers are part of a character field (in an address, for example), they are sorted alphabetically (1, 10, 101, 11, 12, 121, 2, 3,...).
Nulls in a character field are sorted last.
Sort Precedence in JoinDef Execution
QBF sorts Master/Master JoinDefs in the same way as tables. The fields can be sorted in any order.
In Master/Detail JoinDefs, the sorting sequence in a master field must have a higher precedence (lower sort priority number) than a sorting sequence assigned to a detail field. This rule ensures that the detail field remains subordinate to the master field.