ORDER BY clause
Use the ORDER BY clause to sort the resulting view that is based on expression results. The result is sorted by ascending or descending order.
You can use the ORDER BY clause on one or more columns.
Use the GROUP BY and ORDER BY clauses in a single query.
Sort in ascending or descending order by appending the ASC or DESC keyword to the ORDER BY clause.
Examples of ORDER BY clauses
To query AQL to return results in descending order, use the following syntax:
SELECT sourceBytes, sourceIP
FROM flows
WHERE sourceBytes > 1000000
ORDER BY sourceBytes DESC
To display results in ascending order, use the following syntax:
SELECT sourceBytes, sourceIP
FROM flows
WHERE sourceBytes > 1000000
ORDER BY sourceBytes ASC
SELECT sourceIP, SUM(sourceBytes)
FROM flows
GROUP BY sourceIP
ORDER BY SUM(sourceBytes) DESC
When you use the GROUP BY clause with a column name or AQL function, only the first value is returned for the GROUP BY column, by default, even though other values might exist.
When you use a time field in the ORDER BY clause, use a simple datetime field, such as starttime. Using a formatted datetime field can impact the performance of the search.