Sorting result table rows
To specify how you want the rows in a result table to be ordered, specify a SELECT statement with an ORDER BY clause.
After following the steps in this section, you will have created the following query:
SELECT STAFF.NAME, STAFF.ID STAFF.DEPT, STAFF.JOB
STAFF.SALARY, STAFF.COMM, STAFF.YEARS
FROM STAFF
ORDER BY STAFF.DEPT ASC,
STAFF.NAME ASC
The query
This query returns staff records that are sorted first by department number in ascending order and then by name in ascending order.
1. Create a new SELECT statement and select the STAFF table from the Tables/views list.
2. Select Select all in table > STAFF from the pop-up menu on the Columns list.
Although this query selects all of the columns in the table, do not use the SELECT * check box. Unlike *, selecting the columns individually enables you to change the sequence of the columns as they will appear in the result table.
Specifying the sequence of columns
Use the pop-up menu on the Column sequence list to change the sequence of the columns to match the example statement you are working on. For example, select STAFF.NAME in the Column sequence list and select Move before > STAFF.COMM. Then select STAFF.COMM in the Column sequence list and select Move after > STAFF.SALARY.
Using the ORDER BY Details window
After you have the columns in the proper sequence, you are ready to specify the order of the result table rows using an ORDER BY clause.
1. Select ORDER BY from the Clause menu.
This displays the ORDER BY Details window, which looks like this:
The ORDER BY Details window enables you to specify how you want to sort the rows of the result table.
2. Select STAFF.DEPT and STAFF.NAME in the Columns list. Each column you select is added to the ORDER BY sequence list in the order it is selected.
Specifying the sorting order and precedence
Use the pop-up menu on the ORDER BY sequence list to specify the sorting order and precedence.
1. Select an item in the ORDER BY sequence list and select Ascending (ASC) to specify an ascending sort order or Descending (DESC) to specify a descending sort order.
The order of the items in the ORDER BY sequence list determines the sorting precedence. Use Move after and Move before to change the order of the items in the list.
2. If necessary, use the pop-up menu to adjust the ORDER BY sequence list.
3. Select Apply to save the ORDER BY clause and return to the SELECT Details window. If you want, name and save your query.
Last modified date: 06/01/2018