Wednesday 29 May 2013

SORTING in SQL

The default sort order is ascending:

  • Numeric values are displayed with the lowest value first e.g. 1-10
  • Date values are displayed with the earliest value first e.g. 01-JAN-12 before 12-FEB-13
  • Character values are displayed in alphabetical order e.g. A first Z last
  • Null values are displayed last for ascending sequence and first for descending sequence.
Sorting in DESCENDING Order


Sorting by Column Alias

We can use a column alias in the ORDER BY clause. The below example sorts the data by Annual Salary.

Example:


Sorting By Multiple Columns:

We can sort query by more than one column. The sort limit is the number of columns in the given table.

Example:





No comments:

Post a Comment