Sorting

Similar to an ORDER BY clause in a typical SQL query, Athena allows sorting of results using the SORT function, which can be used multiple times in the same query.

Syntax

The SORT function takes two arguments. The first argument is an identifier that references a field physically present in the schema. The second argument specifies the sorting direction and can be either asc for ascending or desc for descending. When left out, the asc direction is assumed.

SORT(field1, ASC|DESC) SORT(field2, ASC|DESC)

Example: Listing objects sorted by the last modification date in descending order.

SORT(updatedAt, DESC)