SELECT - SQL Command - ORDER BY Clause

The ORDER BY clause specifies one or more items used to sort the final query result set and the order for sorting the results.

NoteNote

If you do not specify an order in the ORDER BY clause, query results appear in no order.

For the complete syntax, see SELECT - SQL Command.

The detailed syntax for the ORDER BY clause appears as follows:

[ORDER BY Order_Item [ASC | DESC] [, ...]]

Parameters

[ORDER BY Order_Item

Specifies the item used to sort the final query result set.

  • A field in a FROM table or a subquery. You cannot specify a Blob or General type field.

    NoteNote

    If the ORDER BY clause is applied to a UNION operation, the field should also be a Select_Item in the last SELECT clause, not a subquery.

  • A field alias from the SELECT list.

    NoteNote

    If the ORDER BY clause is applied to a UNION operation, the alias should be a Select_Item in the last SELECT clause.

  • A numeric expression indicating the location of the column in the result table. The leftmost column is number 1.

[ASC]

Specifies an ascending order for the query results. ASC is the default order for ORDER BY.

[DESC]

Specifies a descending order for the query results.

Expand imageRemarks

Expand imageExample

Expand imageSee Also


© , 1996-2020 • Updated: 11/10/20
Comment or report problem with topic