ORDER BY

ORDER BY allows you to sort the results of a query in ascending or descending order.

ORDER BY is specified by the column name or an integer representing the column in the order it is listed in the query. Use the integer when you don't know the column name returned from an expression. ORDER BY must also be a constant, not an expression. ORDER BY supports multiple columns and integers.

ORDER BY is not sorted on columns as they exist in the table but how they are listed in the select statement. If the query is to return results using alias names for the columns, ORDER BY will be done on the alias names.

SELECT state,city, hhinc, pop  FROM table ORDER BY state ASC, city ASC

Spectrum Spatial handles null values in an ORDER BY or ORDER BY <ASC> by adding them at the bottom of the list of results. ORDER BY <DESC> will return the values at the top. This behavior applies to all supported data source providers, except TAB where null values are not applicable.

ORDER BY can be delegated to a data source provider if the data provider supports it. For more on delegation, see Delegation Rules: ORDER BY.

ORDER BY can still be delegated even if the WHERE clause cannot be delegated.