Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: Command Index > S > SELECT


Scroll Prev Top Next More

This clause specifies how to sort the result of the SELECT command.







Indicates that this part of the command is repeatable.




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



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



Sorts by any column name or combination of column names.



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 condition because it uses the least disk space necessary to sort data; however, the SET SORT ON condition is slower than the automatic sort.




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 +



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 +