Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: Command Index > O

ORDER BY

Scroll Prev Top Next More

Use the ORDER BY clause with an R:BASE command to specify the order in which rows of data from a table are displayed.

 

ORDERBY

 

Options

 

,

Indicates that this part of the command is repeatable.

 

ASC

DESC

Specifies whether to sort a column in ascending or descending order.

 

#c

Takes the place of a column name and refers to the column numbers displayed with the LIST TABLE command.

 

colname

Sorts by any column name or combination of column names.

 

seq_no

Refers to the items listed in the SELECT command that is using the ORDER BY command, ordered from left to right. An item can be a column name, expression, or SELECT function.

 

About the ORDER BY Command

 

The syntax for the ORDER BY clause is the same for all commands. ORDER BY must refer to only one table or view.

 

You can significantly reduce the time R:BASE takes to process an ORDER BY clause when the column or columns listed in the ORDER BY clause are included in an index with the same column sort order as that specified in the ORDER BY clause.

 

Using the SET SORT Command

The ORDER BY command uses the R:BASE automatic sort optimizer. If you are sorting extremely large tables, and if your disk space is limited, the automatic sort optimizer might be unable to sort the data. Instead, use the SET SORT ON command because it uses the least disk space necessary to sort data; however, the SET SORT ON command is slower than the automatic sort.

 

Examples

 

The following command displays data from the custid, company, and custcity columns from the customertable.

 

SELECT custid, company, custcity FROM customer

 

The ORDER BY clause in the command below arranges the custidvalues in descending order.

 

SELECT custid, company, custcity FROM customer +

ORDER BY custid DESC

 

You can substitute a column's sequence number for a column named in the ORDER BY clause. You must use a sequence number when referring to an expression, function, constant, or when a UNION operator is used. The following command is equivalent to the command example above.

 

SELECT custid, company, custcity FROM customer +

ORDER BY 1 DESC