Versions available for this page: CUBRID 8.2.1 | CUBRID 8.3.0 | CUBRID 8.3.1 | CUBRID 8.4.0 | CUBRID 8.4.1 | CUBRID 8.4.3 | CUBRID 9.0.0 |
The ORDER BY clause sorts the query result set in ascending or descending order. The ORDER BY clause must be placed at the end of the query statement. If the ORDER BY clause is not specified, the order of instances to be queried may vary depending on query.
ORDER BY sort_spec [ {, sort_spec} ]
sort_spec :
integer_literal [ ASC | DESC ]
expression [ ASC | DESC ]
alias [ ASC | DESC ]
Each field in the ORDER BY clause must be separated by a comma (,). If the keyword DESC is not specified after expression or integer_literal in the ORDER BY clause, the query result is returned in ascending order.
SELECT host_year, host_nation FROM olympic ORDER BY host_nation;
=== <Result of SELECT Command in Line 2> ===
host_year host_nation
===================================
2000 'Australia'
1956 'Australia'
1920 'Belgium'
1976 'Canada'
1952 'Finland'
...
25 rows selected.
SELECT host_year, nation_code, gold FROM participant WHERE gold BETWEEN 10 AND 15
ORDER BY 3 DESC, 2;
=== <Result of SELECT Command in Line 1> ===
host_year nation_code gold
================================================
1996 'FRA' 15
1992 'CUB' 14
1992 'ESP' 13
2000 'FRA' 13
2000 'GER' 13
2004 'GER' 13
...
20 rows selected.