Export (0) Print
Expand All

ORDER BY Clause

SQL Server 2000

Specifies the sort order for the result set. The ORDER BY clause is not valid in subqueries.

Syntax
[ ORDER BY { order_by_expression [ ASC | DESC ] }     [ ,...n] ] 
Arguments
order_by_expression
Specifies a column on which to sort. A sort column can be specified as a name or column alias (which can be qualified by the table name) or an expression. Multiple sort columns can be specified. The sequence of the sort columns in the ORDER BY clause defines the organization of the sorted result set.

The ORDER BY clause can include items not appearing in the select list.

Note  ntext and image columns cannot be used in an ORDER BY clause.

ASC
Specifies that the values in the specified column should be sorted in ascending order, from lowest value to highest value.
DESC
Specifies that the values in the specified column should be sorted in descending order, from highest value to lowest value. Null values are treated as the lowest possible values.
There is no limit to the number of items in the ORDER BY clause.
Examples

The following example lists employees by their first names.

SELECT FirstName + ' ' + LastName FROM Employees ORDER BY FirstName

Show:
© 2014 Microsoft