Order By Clause

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

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;

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.