State about ORDER BY Clause

     

     

    Facts about ORDER BY Clause

     

  • The SQL ORDER BY clause is used with the SQL SELECT statement
  • It indicates about the sort order for result set
  • Order by clause sorts the result set by a specified column
  • Order by clause can sort the column data in
  •  

    (1)Ascending to Descending Order (2)Descending to Ascending Order

     

     

  • Data will be sorted either by alphabhets/Numerics based on content of column
  • When multiple columns are used in ORDER BY CLAUSE, the first column will be sorted fully and rest of columns will be sorted based on previous columns
  • While executing the query we can assign Column Name/Column Number
  • Example

    Select * from sales order by Quantity (or)
    Select * from sales order by 3
    Note: The number is based on Columns mentioned in SELECT list not a Table.

 

 

Order by Clause
Ascending
Descending
ASC is abbrevated as Ascending Order
DSC is abbrevated as Descending Order
Results will be shown in Ascending Order
Results will be shown in Descending Order
In case of dates (Date data type) EARLIEST date show on TOP
In case of dates (Date data type)LATEST date shown on TOP
In case of Numeric data type LOWEST values are shown on TOP
In case of Numeric data type HEIGHEST values are shown on TOP
In case of STRING data type query result starts with letter Z to A
pending

 

Order by Clause Syntax:

Note: WHERE Conditon is OPTIONAL