Creating an ORDER BY clause in a FULLSELECT statement
The ORDER BY clause specifies the order of the rows of a results table for an SQL statement.
If a single sort specification is identified, the rows are ordered by the values of that sort specification. If more than one sort specification is identified, the rows are ordered by the values of the first indicated sort specification, then by the values of the second identified sort specification, and so on. The ORDER BY clause can be set for both SELECT and FULLSELECT statements.
You cannot have an ORDER BY clause on SELECT statements within the FULLSELECT statement. The ORDER BY applies to the final result set from the FULLSELECT statement. You can sort on either a single column or multiple columns.
To create an ORDER BY clause in a FULLSELECT statement:
- Switch to the Data perspective.
- Create the FULLSELECT statement.
- Open the FULLSELECT statement in the SQL Builder.
- Add SELECT statements as required.
- To sort on a single column, do the following:
- Make sure you are in the FULLSELECT editor pane by clicking the FULLSELECT statement in the Outline view.
- In the SQL Builder, click the first cell under the Column heading, and then click again to open the list of available columns.
- Click the column or enter a column expression on which you want to sort.
- Click the Sort Type cell, and then select either Ascending, Descending, or Default. The Default option indicates that sorting is required, but no SQL source should be shown for the sort type. The default sort type for your database product is used.
- Press Enter
- Click the cell under the Sort Order heading.
- Select the number that corresponds to the order in which to sort the results, and then press Enter.
- To sort on multiple columns, do the following. To sort on columns in a FULLSELECT statement that have the same ordinal value but are in different sub-SELECT statements, the columns must have the same name. If the columns have different names in their corresponding sub-SELECT statements, assign the same alias to each of the columns.
- In the Outline view, click the SELECT statement that contains on which to sort.
- In the Tables pane, select the check boxes beside the columns to use in your statement.
- On the Columns page in the SQL Builder, select the column on which to sort, and then click the Alias cell.
- Type an alias for this column, and then press Enter.
- Repeat these steps for the other columns on which to sort in the other sub-SELECT statements. Make sure that you use the same alias for each of the multiple columns. After you have defined all the columns on which to start, you are ready to create the ORDER BY clause.
- In the Outline view, select the FULLSELECT statement.
- On the Columns page in the SQL Builder, click the first cell under the Column heading, and then click again to open the list of available columns.
- Select the first column on which to sort. This is the first column to which you added the alias.
- Click the Sort Type cell, and select either Ascending, Descending, or Default. The Default option indicates that sorting is required, but no SQL source should be shown for the sort type. The default sort type for your database product is used.
- Press Enter
- Click the cell under the Sort Order heading.
- Select the number that corresponds to the order in which to sort the results, and then press Enter.
- Repeat these steps with other columns until you have created the sort order for the statement results.
Parent topic
Creating a FULLSELECT statement