SQL/MP Query Guide
Retrieving Data: How to Write Queries
HP NonStop SQL/MP Query Guide—524488-003
1-5
Organizing Results
The WHERE clause, used in these examples, is described in Specifying Search
Conditions on page 1-8.
The ORDER BY Clause
If you want your report to list employees from highest paid to lowest paid, you can add
an ORDER BY clause, as shown in Example 1-1. The DESC keyword tells SQL to sort
in descending order; the report lists Ben Henderson, who makes $65,000, before Mary
Miller, who makes $56,000. (If you omit the DESC keyword, the ORDER BY clause
automatically sorts in ascending order.)
When evaluating the ORDER BY clause, SQL considers all null values to be equal.
Null values are considered greater than nonnull values.
If a collation is specified as part of the ORDER BY clause in a SELECT statement, the
character set associated with the collation must be the same as the character set
associated with the column in the SELECT statement.
Example 1-1. SELECT Statement With ORDER BY Clause
SELECT LAST_NAME, FIRST_NAME, SALARY
FROM EMPLOYEE
WHERE SALARY > 50000
ORDER BY SALARY DESC ;
LAST_NAME FIRST_NAME SALARY
------------- ------------- ----------
GREEN ROGER 175500.00
. . .
. . .
. . .
HENDERSON BEN 65000.00
MILLER MARY 56000.00
--- 16 row(s) selected.