Hello, I'm trying to produce a sorted list of results with MonetDB/XQuery using 'order by', with a query that goes something like this: for $cname in pf:collections()/text() return if (local:is-date-between($cname, **start_date_here**, **end_date_here**)) then for $s in pf:collection($cname)//Dublin/stations[time/hour=13 and time/minute>=22 and time/minute<=25] order by $s/timeOfDay return $s else () ...the 'is-date-between' is just some custom function to check if the $cname (collection names are dates) is between the start and end dates supplied to the function. However, the problem is with the nested for loop. I want each $s that satisfies the XPath expression to be returned, but ordered by $s/timeOfDay. When I submit this query, I get the following error: ERROR = !type error: [err:XPTY0004] Orderspec requires at most one atomic item (given: string*). I've tried a number of variations on this, but the error is always the same. If I remove the order by clause, the results will return correctly, but in the unsorted order that they appear in the database. I'm still a beginner with XQuery, so I'm unsure where I'm going wrong, and documentation and tutorials have been unhelpful so far. Any help is appreciated! Regards, -Rob