ORDER BY Clause in DB2
The ORDER BY Clause is used to sort the
result-set in a specified order (Ascending or Descending). By default ORDER BY
Clause sorts the result-set in ascending order.
ORDER BY Column-name/column-number ASC/DESC
For example, we have following table Orders as
We want to sort the result set by Customer Name
in Ascending Order :
* we don't need to specify ASC, because ORDER
BY clause sorts the result table in ascending order implicitly.
Now, we want to sort the result set by Customer Name in Descending Order :
This time, we want to sort the result table by
Date that recently placed order comes first in the result table :