Entering content frame

This graphic is explained in the accompanying text ORDER BY Clause Locate the document in its SAP Library structure

The ORDER BY clause allows to retrieve the rows of a result set in a specified order.

This graphic is explained in the accompanying text

It is good programming style to use an ORDER BY clause only if the database can cheaply do the sorting using a suitable index.

Syntax

This graphic is explained in the accompanying text

<order by clause> ::=
         ORDER BY <sort specification>
                       ( ',<sort specification> )*.

<sort specification> ::=
         <display name> ( ASC | DESC )?.

<display name> is the name of a column in the result set. Ordering with respect to undefined <display name>s is not possible as this column cannot be named in a <sort specification>.

If a <display name> is ambiguous (e.g. the same name is used in different <as clause>'s in the same statement) it cannot be used in a <sort specification>.

Example

This graphic is explained in the accompanying text

SELECT employee_name, salary AS sal
               FROM employees
              ORDER BY sal DESC

ORDER BY Clause. This query selects the name and the salary of all employees. The result set is sorted descending by the salary.

See

Select List

Leaving content frame