Once a query has been defined using the above query elements, the result is a set of items. Using the ORDER BY directive, the results may be ordered by the item’s properties. For example:

age > 30 ORDER BY firstName

This will return all people for whom age is greater than 30, with the results ordered by the firstName property in ascending order. The results may be ordered in descending order by adding SORT DESC to the end of the directive:

age > 30 ORDER BY firstName SORT DESC

The SORT ASC directive may also be used, but it’s unnecessary because it’s already the default.

The results may be ordered by multiple properties, each in ascending or descending order. For example:

age > 30 ORDER BY lastName, firstName SORT DESC

This will order the results by lastName. If multiple results have the same lastName, then within their group they will be ordered by firstName in descending order.

A further directive, CASE IGNORECASE, may be used for case-insensitive sorting:

age > 30 ORDER BY firstName SORT ASC CASE IGNORECASE

Note that you can omit the tokens SORT and CASE, unless you are using parameters for the ASC/DESC or USECASE/IGNORECASE tokens.

 
loading table of contents...