XQuery order by ascending and descending

Tuffy G picture Tuffy G · May 14, 2011 · Viewed 41k times · Source

In XQuery, How do you order by ascending and descending?

I have got the following from a tutorial:

for $x in doc("books.xml")/bookstore/book
where $x/price>30
order by $x/title
return $x/title

would it be

for $x in doc("books.xml")/bookstore/book
where $x/price>30
order by $x/title ascending
return $x/title

Answer

Lucero picture Lucero · May 14, 2011

Yes, you can use ascending (default) or descending at the end of the order by.. expression.

Here's the link to the relevant part of the W3C XQuery spec:

http://www.w3.org/TR/xquery/#doc-xquery-OrderSpec