CoderZone.org

Category: >> Oracle PL/SQL >> ORDER BY Clause Bookmark and Share

<< lastnext >>

Snippet Name: ORDER BY Clause

Description: The ORDER BY clause is used by, and is the last clause of, a SELECT statement.

Comment: (none)

Author: CoderZone
Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 16th, 2009

ascending ORDER ON one column -
 
SELECT table_name
FROM user_tables
ORDER BY table_name ASC;
 
ascending ORDER IS the DEFAULT so this can also be written -
 
SELECT table_name
FROM user_tables
ORDER BY table_name;
 
 
ORDER BY descending
 
SELECT table_name
FROM user_tables
ORDER BY table_name DESC;
 
 
ORDER BY Multiple Columns
 
SELECT table_name, tablespace_name
FROM all_tables
ORDER BY tablespace_name, table_name;
 
 
ORDER BY Multiple Columns WITH Mixed Ascending AND Descending 
Orders 
 
SELECT table_name, tablespace_name
FROM all_tables
ORDER BY tablespace_name DESC, table_name; 
 
ORDER BY position
 
Single Column Ascending 
 
SELECT table_name
FROM all_tables
ORDER BY 1; 
 
Single Column Descending 
 
SELECT table_name, tablespace_name
FROM all_tables
ORDER BY 2 DESC; 
 
ORDER BY Multiple Columns 
 
SELECT table_name, tablespace_name
FROM all_tables
ORDER BY 2, 1; 
 
 
 
 
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 20