Your browser does not support JavaScript. This help page requires JavaScript to render correctly. Sorting Selected Data
Skip Headers
Previous
Previous
 
Next
Next

Sorting Selected Data

When the results of a query are displayed, records can be in any order, unless you specify their order with the ORDER BY clause.

The results of the query in the following example are sorted by LAST_NAME, in ascending order (the default).

Alternatively, in SQL Developer, you can omit the ORDER BY clause and double-click the name of the column to sort.

Sorting Selected Data by LAST_NAME

SELECT FIRST_NAME, LAST_NAME, HIRE_DATE
FROM EMPLOYEES
ORDER BY LAST_NAME;

Result:

FIRST_NAME           LAST_NAME                 HIRE_DATE
-------------------- ------------------------- ---------
Ellen                Abel                      11-MAY-96
Sundar               Ande                      24-MAR-00
Mozhe                Atkinson                  30-OCT-97
David                Austin                    25-JUN-97
Hermann              Baer                      07-JUN-94
Shelli               Baida                     24-DEC-97
Amit                 Banda                     21-APR-00
Elizabeth            Bates                     24-MAR-99
...
FIRST_NAME           LAST_NAME                 HIRE_DATE
-------------------- ------------------------- ---------
Jose Manuel          Urman                     07-MAR-98
Peter                Vargas                    09-JUL-98
Clara                Vishney                   11-NOV-97
Shanta               Vollman                   10-OCT-97
Alana                Walsh                     24-APR-98
Matthew              Weiss                     18-JUL-96
Jennifer             Whalen                    17-SEP-87
Eleni                Zlotkey                   29-JAN-00

107 rows selected

The sort criterion need not be included in the select list, as the following example shows.

Sorting Selected Data by an Unselected Column

SELECT FIRST_NAME, HIRE_DATE
FROM EMPLOYEES
ORDER BY LAST_NAME;
 

Result:

FIRST_NAME           HIRE_DATE
-------------------- ---------
Ellen                11-MAY-96
Sundar               24-MAR-00
Mozhe                30-OCT-97
David                25-JUN-97
Hermann              07-JUN-94
Shelli               24-DEC-97
Amit                 21-APR-00
Elizabeth            24-MAR-99
...
FIRST_NAME           HIRE_DATE
-------------------- ---------
Jose Manuel          07-MAR-98
Peter                09-JUL-98
Clara                11-NOV-97
Shanta               10-OCT-97
Alana                24-APR-98
Matthew              18-JUL-96
Jennifer             17-SEP-87
Eleni                29-JAN-00
 
107 rows selected.

Related Topics

Oracle Database SQL Language Reference

Selecting Table Data