SQL-J Language Reference,
Page 41 of 118


[top]
[prev]
[next]
Documentation Top
Global Index
Reference Manual
TOC Index
Grammar index
Developer's Guide
TOC Index
Tuning Cloudscape
TOC Index

ORDER BY clause

The ORDER BY clause is an optional element of a SELECT statement. An ORDER BY clause allows you to specify the order in which rows appear in the ResultSet.

Syntax

ORDER BY { ColumnName | ColumnPosition }
    [ ASC | DESC ]
    [ , ColumnName | ColumnPosition
        [ ASC | DESC ] ] *

ColumnPosition is an integer that refers to the number of the column in the SelectItem in the underlying Query of the SELECT statement (numbering starts at 1). (In other words, if you want to order by a column, that column must be in the select list.)

ColumnName refers to the names visible from the SelectItems in the underlying query of the SELECT statement. (In other words, if you want to order by a column, that column must be in the select list.)

ASC specifies that the results should be returned in ascending order; DESC specifies that the results should be returned in descending order. If the order is not specified, ASC is the default.

An ORDER BY clause prevents a SELECT statement from being an updatable cursor. (For more information, see “Requirements for Updatable Cursors”.)

For ORDER BY, NULLs sort low. For example, if an INTEGER column contains integers, NULL is considered less than 1 for purposes of sorting.

You cannot ORDER BY a Java data type unless the data type is orderable (see “Orderable Java Data Types”).

NEW: The ability to order by some Java data types is new in Version 3.0.

Example

SELECT hotel_name, normal_rate
FROM Hotels
ORDER BY 2 DESC
SELECT city.getName(), city.getDisplayCountry() AS COUNTRY
FROM Cities
ORDER BY COUNTRY
-- order by an Orderable Java data type
SELECT *
FROM Cities
ORDER BY City
[top]
[prev]
[next]


Cloudscape Version 3.0
For technical support, go to: www.cloudscape.com and click Support.
Copyright © 1998 and 1999 Cloudscape, Inc. All rights reserved.