SQLite ORDER BY Clause

The SQLite ORDER BY clause is used to sort the fetched data in ascending or descending order, based on one or more column.

Syntax:

snippet
SELECT column-list 
FROM table_name 
[WHERE condition] 
[ORDER BY column1, column2, .. columnN] [ASC | DESC];

You can use one or more columns in ORDER BY clause. Your used column must be presented in column-list.

Let's take an example to demonstrate ORDER BY clause. We have a table named "STUDENT" having the following data:

Sqlite Order by clause 1

Example1:

Select all records from "STUDENT" where FEES is in ascending order:

snippet
SELECT * FROM STUDENT ORDER BY FEES ASC;

Output:

Sqlite Order by clause 2

Example2:

Fetch all data from the table "STUDENT" and sort the result in descending order by NAME and FEES:

snippet
SELECT * FROM STUDENT ORDER BY NAME, FEES DESC;

Output:

Sqlite Order by clause 3
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +