The #:order clause specifies the order in which query results should be returned.
The clause is a list of order terms, each of which can be one of the following:
(order expr direction)
Sort by expr, where expr is an attribute or expression. direction can be the literal 'asc (ascending order):
( (select #:from person #:order ((order person.age 'asc))))
the literal 'desc (descending order):
( (select #:from person #:order ((order person.age 'desc))))
or an unquoted Scheme expression evaluating to 'asc or 'desc:
( (select #:from person #:order ((order person.age ,( "asc")))))
Shorthand for (order expr 'asc).
Shorthand for (order expr 'desc).
When multiple terms are specified, they are treated in descending order of precedence. For example, the expression:
|( (select #:from person|
|#:order ((desc person.age)|
would return a ( person) sorted first by descending age, then by alphabetical surname.
Note that the SQL-97 standard dictates that expressions and attributes in the #:order clause must appear in the #:what clause. Expressions must be aliased so the DBMS can match the two clauses up.
|( ([x ( ( person.age person.shoe-size))])|
|( (select #:what x|
|#:order ((asc x)))))|