skip to main content
SQL Statements for Flat-File Drivers : Select Statement : Order By Clause
  
Order By Clause
The Order By clause indicates how the rows are to be sorted. The form is:
ORDER BY {sort_expression [DESC | ASC]}, ...
sort_expression can be field names, expressions, or the positioned number of the column expression to use.
The default is to perform an ascending (ASC) sort.
For example, to sort by last_name and then by first_name, you could use either of the following Select statements:
SELECT emp_id, last_name, first_name FROM emp
ORDER BY last_name, first_name
or
SELECT emp_id, last_name, first_name FROM emp
ORDER BY 2,3
In the second example, last_name is the second column expression following Select, so Order By 2 sorts by last_name.