SIGN UP MEMBER LOGIN:
   
ARTICLE

ORDER BY Clause in DB2

Posted by Deepak Kumar Articles | DB2 May 02, 2011
ORDER BY Clause is used to sort the output rows in ascending or descending order. The use of ORDER BY Clause is discussed in nutshell .....
Reader Level:

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.

Syntax:

ORDER BY Column-name/column-number ASC/DESC

For example, we have following table Orders as :

ORDERBY1.gif 

We want to sort the result set by Customer Name in Ascending Order :

ORDERBY2.gif 

* 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 :

ORDERBY3.gif 

This time, we want to sort the result table by Date that recently placed order comes first in the result table :

 ORDERBY4.gif

Login to add your contents and source code to this article
This Feature is Sponsored By
post comment
COMMENT USING