Datasheet

Writing Simple Queries
39
default. The ORDER BY clause follows the FROM clause and the WHERE clause in the SELECT
statement.
To retrieve all employee names of department 90 from the
EMPLOYEES table ordered by
last name, use this query:
SELECT first_name || ‘ ‘ || last_name “Employee Name”
FROM employees
WHERE department_id = 90
ORDER BY last_name;
Employee Name
----------------------------------------------
Lex De Haan
Steven King
Neena Kochhar
SQL>
You can specify more than one column in the ORDER BY clause. In this case, the result
set will be ordered by the first column in the
ORDER BY clause, then the second, and so on.
Columns or expressions not used in the
SELECT clause can also be used in the ORDER BY
clause. The following example shows how to use
DESC and multiple columns in the ORDER
BY
clause:
SELECT first_name, hire_date, salary, manager_id mid
FROM employees
WHERE department_id IN (110,100)
ORDER BY mid ASC, salary DESC, hire_date;
FIRST_NAME HIRE_DATE SALARY MID
-------------------- --------- ---------- ----------
Shelley 07-JUN-94 12000 101
Nancy 17-AUG-94 12000 101
Daniel 16-AUG-94 9000 108
John 28-SEP-97 8200 108
Jose Manuel 07-MAR-98 7800 108
Ismael 30-SEP-97 7700 108
Luis 07-DEC-99 6900 108
William 07-JUN-94 8300 205
8 rows selected.
SQL>
95127c01.indd 39 2/18/09 6:37:10 AM