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.
Note |
|---|
|
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.
Note 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.
Note 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.
Remarks
Example
See Also
© , 1996-2020 • Updated: 11/10/20
Comment or report problem with topic
Microsoft Visual FoxPro 9 SP2 Help file, VFPX Edition v1.08