OrderByClause

Order intermediate results.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


Syntax

OrderByClause

graphics/OrderByClause.png

SortSpecList

Description

In a FLWOR expression, an OrderByClause sorts the intermediate result tuples before passing them to the return clause where the output sequence is constructed.

Example

See FLWORExpr and SortSpecList for examples.

  • List book titles with their year of publication, newest first:

    for $a in input()/bib/book
    order by $a/@year descending
    return ($a/@year, $a/title)
  • List book titles sorted according to French collation:

    for $a in input()/bib/book
    order by $a/title ascending collation "collation?language=fr"
    return $a/title

    Since ascending is the default order modifier, the order by clause could also read:

    order by $a/title collation "collation?language=fr"