Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XQuery order by ascending and descending

Tags:

xml

xquery

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
like image 943
Tuffy G Avatar asked May 14 '11 10:05

Tuffy G


People also ask

How do I sort in XQuery?

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.

How do you use an order by in FLWOR expression?

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.

What is ascending order?

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.

What is XQuery used for in XML file?

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.


2 Answers

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

like image 108
Lucero Avatar answered Sep 27 '22 01:09

Lucero


See my answer to this question. The code demonstrates ordering in descending order.

For ordering in ascending order, the ascending keyword can be ommitted.

like image 22
Dimitre Novatchev Avatar answered Sep 23 '22 01:09

Dimitre Novatchev