Order by Clause

The optional order by clause enables you to sort the results in ascending or descending order.

In a continuous query, each set of ordered results in a window constitutes one batch of results. For an example, see Example Showing Batching of Return Values (Continuous Queries).

See also Limit Clause.

Examples

Pound or hash (#) is the escape character. See Keywords and Other Reserved Words.

In the following example, each row in the result shows the ID of a customer who has placed three or more orders each of which contained 5 or more lines.

order by A.State, C, D, E
order by A@extId, B.name {limit : first 10}
select o.customerId as cid
from /Concepts/#Order o
where o.lines@length >= 5
group by o.customerId
having count(*) >= 3
order by cid desc;