SQL ORDER BY

SQL ORDER BY

Oracle allow data from a table to be viewed in a sorted order. The rows retrieved from the table will be sorted in either ascending or descending order depending on the condition specified in the SELECT statement. Syntax

SELECT * FROM <TableName> ORDER BY <ColumnName1>,<ColumnName2> <[Sort Order]>

The ORDER BY clause will sorts the data based on the column specified after the ORDER BY clause. Note: The ORDER BY clause can only be used in the SELECT statements.

Example for Ascending Order

SELECT * FROM EMPLOYEE ORDER BY FIRSTNAME, LASTNAME ASCE

ORDER BY will sort the data ascending order if we will not specify the any order in the statement

Example for Descending Order

SELECT * FROM EMPLOYEE ORDER BY FIRSTNAME, LASTNAME DESC

 

Leave a Reply