Sorting Data

Amazon SimpleDB supports the sorting of data on a single attribute, in ascending (default) or descending order. This section describes how to sort the result set returned from Query.

[Note]Note

All sort operations are performed in lexicographical order.

The sort attribute must be present in at least one of the predicates of the query expression.

Sort cannot be applied to query expressions that contain UNION or NOT predicate operators.

The following table shows sort queries, how they are interpreted, and the results they return from the sample dataset.

Query ExpressionDescriptionResult
['Year' > '1980'] sort 'Year' asc

Retrieves all items released prior to 1980 and lists them in ascending order.

0802131786, 0385333498, 1579124585
['Year' > '1980'] sort 'Year'

Same as the previous entry, with "asc" (ascending) omitted.

0802131786, 0385333498, 1579124585
['Year' = '2007'] intersection ['Author' starts-with ''] sort 'Author' desc

Retrieves all items released in 2007 and sorts them by author name in descending order.

B00005JPLW, B000T9886K