The ORDER BY clause specifies the sorting sequence used for the result-set. The sequence is specified as a list of members of the extents used in the FROM clause. You can specify whether the query uses ascending or descending order by using the keywords ASC or DESC respectively. If you do not specify the order, the default value is ascending. The first member name listed is the primary sequence. Additional member names, if used, specify secondary sort sequences. Specifying an ORDER BY clause may adversely affect the performance of a query. Extents can be indexed to optimize orderings that you often use.
The ORDER BY keywords are as follows:
- ASC - ascending sort order
- DESC - descending sort order
The following example query uses the ORDER BY clause:
SELECT * FROM ProductExtent AS product ORDER BY product.unitPrice ASC, product.productName DESC
In the above example query, the result-set is first sorted by unit price in ascending order (primary sort order), then by name in descending order (secondary sort order).