Order By

Home > Query Language > Details of the Query Language > Order By

The "orderby" clause is optional. As its name suggests, the "orderby" clause orders the values or objects returned by the query. If the "orderby" clause contains multiple elements, the left-to-right sequence of the elements determines the high-to-low precedence. The "asc" keyword specifies ascending order (the default), and the "desc" keyword indicates descending order.

Query(
   from(Person.CID),
   orderby(
      desc( P(Person.P.yearOfBirth) ),
      asc( P(Person.P.lastname) )
   )
);

Aggregate functions may be part of an "orderby" clause, but this makes sense only in the presence of grouping conditions. For sure, these aggregate functions must be part of the "select" clause as well.

Query(
   select( P(Person.P.yearOfBirth), countAgg() ),
   from(Person.CID),
   orderby(
      asc( countAgg() )
   )
);

Next chapter: Example Queries

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.