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
Sorting in XQuery The only way to sort data in an order other than document order is by using the order by clause of the FLWOR. Therefore, in some cases it is necessary to use a FLWOR where it would not otherwise be necessary.
An order by clause in a FLWOR expression specifies the order in which values are processed by the return clause. If no order by clause is present, the results of a FLWOR expression are returned in a non-deterministic order. An order by clause contains one or more ordering specifications.
Definition of in ascending order : arranged in a series that begins with the least or smallest and ends with the greatest or largest The children were lined up in ascending order of height. Test scores are listed in ascending order from lowest to highest.
XQuery is a functional language that is used to retrieve information stored in XML format. XQuery can be used on XML documents, relational databases containing data in XML formats, or XML Databases. XQuery 3.0 is a W3C recommendation from April 8, 2014.
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
See my answer to this question. The code demonstrates ordering in descending order.
For ordering in ascending order, the ascending
keyword can be ommitted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With