ORDER BY Clause


 

 

SQLite: ORDER BY Clause

This SQLite tutorial explains how to use the SQLite ORDER BY Clause with syntax and examples.

 

Description:

The SQLite ORDER BY clause is used to sort the records in your result set.

 
Syntax:

 

Parameters or Arguments:

expressions

The columns or calculations that you wish to retrieve.

tables

The tables that you wish to retrieve records from. There must be at least one table listed in the FROM clause.

conditions

The conditions that must be met for the records to be selected.

ASC

Optional. It sorts the result set in ascending order by expression. ASC is the default, if no modifier is provider.

DESC

Optional. It sorts the result set in descending order by expression.

Note: If the ASC or DESC modifier is not provided in the ORDER BY clause, the results will be sorted by expression in ascending order, i.e., [a – z] for characters or [0 – 9] for numbers(which is equivalent to “ORDER BY expression ASC”).

 

Examples:

  • The following SQLite statement selects all employee’s from the “Employee” table, sorted by the “name” column:

    id name position hire_date
    107 anitha research analyst 1/1/2014
    101 arunesh manager 1/1/2012
    100 chiru developer 1/1/2014
    109 deepak
    104 jaya developer 1/1/2014
    108 kannan 6/1/2013
    106 mathu research analyst 1/1/2013
    102 naga Team Lead 1/1/2013
    103 nithya developer 6/1/2013
    105 uma designer 1/1/2013
  • The following SQLite statement selects all employee’s from the “Employee” table, sorted DESCENDING by the “name” column:

    id name position hire_date
    105 uma designer 1/1/2013
    103 nithya developer 6/1/2013
    102 naga Team Lead 1/1/2013
    106 mathu research analyst 1/1/2013
    108 kannan 6/1/2013
    104 jaya developer 1/1/2014
    109 deepak
    100 chiru developer 1/1/2014
    101 arunesh manager 1/1/2012
    107 anitha research analyst 1/1/2014