By default the objects returned by a query are sorted in ascending order by their id. Use the ‘order by’ clause to specify a different ordering, e.g.:
gn4:story order by gn4:title
returns all the stories in the system sorted in ascending order by their title (a story titled ‘A’ comes before a story titled ‘Z’). Use the ‘descending’ modifier to reverse the sort, e.g.:
gn4:story order by gn4:title descending
returns all the stories in the system sorted in descending order by their title (a story titled ‘Z’ comes before a story titled ‘A’). There is also an ‘ascending’ modifier – e.g.:
gn4:story order by gn4:title ascending
returns all the stories in the system sorted in ascending order by their title as the first example, because sorts by default are ascending.
To sort using multiple attributes just list them separated by comma - each one optionally followed by the ‘descending’ modifier, e.g.:
gn4:story order by gn4:authors descending, gn4:title
returns all stories sorted first by their author names in descending order, and then by their title in ascending order (for those stories that have the same authors).