ORDER BY adjusts the order of rows in the data stream.
Syntax: ORDER BY <expression>
<string>
, <expression>
<string>
, ...
Input:
- <expression>: Sorting basis; multiple bases must be homologous and are operated from left to right
- <alias>: Fashion of sorting, either asc or desc (case insensitive), or asc when omitted
find().nodes([4, 2]) as nodes
n(nodes).e().n(as n) as path
order by n.radius desc, n
return path
In the UQL above, ORDER BY adjusts the order of the one-step paths resulted from template query, first by radius of terminal nodes n in descending order, then by ID of terminal nodes n that share the same radius in ascending order.

ATTR (Numeric value)
Example: Find 10 cards that have the highest balances, i.e, sorts the card balances in a descending order
find().nodes({@card}) as n
order by n.balance desc
return n{*} limit 10
ATTR (Time)
Example: Find cards of Customer CU001, return cards' info in an ascending time order
n({_id == "CU001"}).re({@has}).n({@card} as n)
order by n.open_date
return n{*}
ATTR (String)
Example: Find 10 email addresses, sort them in a descending order of letters from addresses
find().nodes({@email}) as n
limit 10
order by n.address desc
return n{*}
NODE
Example: Find 10 two-step transfer paths, sort paths in a descending order of 2nd nodes' UUIDs
n({@card}).e({@transfer}).n({@card} as n)
.e({@transfer}).n({@card}) as p
limit 10
order by n desc
return p{*}
EDGE
Example: Find 10 two-step transfer paths, sort paths in a descending order of the 2nd edges' UUIDs
n({@card}).e({@transfer}).n({@card})
.e({@transfer} as e).n({@card}) as p
limit 10
order by e desc
return p{*}
GROUP BY and ORDER BY
Example: Sort all cards in groups by their levels, count the number of cards at each level, return the 3 levels with the most cards and card numbers at these levels
find().nodes({@card}) as n
group by n.level as level
return level, count(n) as total limit 3
order by total desc