ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Editors / Query editor / SQL
  • Overview
  • Use format
  • Usage example
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
The ORDER BY clause is used to sort the records selected by an SQL query. The selected records can be sorted in:
  • ascending order (default order):
    • alphabetical order from A to Z for the text items.
    • from the lowest value to the greatest value for the numeric items.
  • descending order:
    • alphabetical order from Z to A for the text items.
    • from the greatest value to the lowest value for the numeric items.
See a specific documentation about SQL for more details.
To discover all the SQL commands (functions, clauses, operators, etc.) that can be used in an SQL query managed by HFSQL, see Commands that can be used in an SQL query managed by HFSQL.
Remarks:
  • This clause can only be used:
    • in the SQL code of queries created in the query editor. Then, these queries will be run by HExecuteQuery.
    • in the SQL code of queries run by HExecuteSQLQuery.
  • This clause can be used with all the types of data sources (Oracle, Access, SQL Server, ...).
  • The sort items specified in the ORDER BY clause may not be found in the SELECT clause (output items of query).
Use format
The format for using the ORDER BY clause is as follows:
ORDER BY ItemToSort ASC/DESC
The <ItemToSort> parameter can correspond to:
  • the name of the item to sort.
  • a parameter name.
    When the query is run, if the parameter contains the sort order (ASC/DESC), this one will have priority over the one specified in the query.
Remark: The ORDER BY clause must always be found after the GROUP BY clause.
Usage example
  • The following SQL code is used to list the last and first names of customers. The result is sorted by customer names in ascending order:
    SELECT CUSTOMER.CustomerLastName, CUSTOMER.CustomerFirstName
    FROM CUSTOMER
    ORDER BY CUSTOMER.CustomerName

    Remark: By default, the sort is performed in ascending order. Therefore, there is no need to specify the ASC keyword.
  • The following SQL code is used to list the products. The result is sorted by product prices in descending order:
    SELECT PRODUCT.ProductName, PRODUCT.ProductPrice
    FROM PRODUCT
    ORDER BY PRODUCT.ProductPrice DESC
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help