Saturday, August 27, 2016

SQL- ORDER BY


ORDER By Clause

When we execute an SQL query , the order of rows returned is not defined or unknown.
To sort the rows using some criteria , use ORDER BY clause.

By default when we use ORDER BY in SQL , rows are ordered in ascending order,
 i.e. ORDER BY  column_name  ASC.

To sort rows in descending order use ORDER BY column_name DESC.

You can also use the position of the column in the select statement instead of column_name in the order by.

 Numeric values are displayed with the lowest values first (for example, 1 to 999).

 Date values are displayed with the earliest value first (for example, 01-JAN-92 before
01-JAN-95).

 Character values are displayed in the alphabetical order (for example, “A” first and “Z”
last).

 Null values are displayed last for ascending sequences and first for descending
sequences.


 You can also sort by a column that is not in the SELECT list.


Examples :







Featured Post

Will the data from Oracle Database be lost after formatting the system in which it is installed?

So Someone asked me a question,  Will the data from Oracle Database be lost after formatting the system in which it is installed? Since the ...

Popular Posts