SimpleDB supports sorting your query results, but please keep in mind that all comparisons of attributes and values are done in the lexicographical fashion that we discussed in the previous chapter. All data that you intend to sort that is not a plain string, but is a date or a number or a Boolean, must be appropriately encoded when storing it and then decoded correctly on retrieval. You can sort data based on a single attribute or the item names, in either ascending or descending order. If you do not specify a sort order, the results are sorted in the ascending order by default. Sorting is done by specifying the keywords order by
and either asc
or desc
in the expression.
SimpleDB provides the following guidelines that you must be aware of when sorting the data:
All sort operations are of course performed in lexicographical order
If you want to sort your results, you must provide the
sort
attribute in at least one of the predicates of the expressionYou can apply sorting to expressions...