ORDER BY Clause in SQLite

SQLite ORDER BY Clause
To sort the fetched data in ascending or descending order, the SQLite ORDER BY clause is used. The sorting can be done based on one or more column.

Syntax:

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

Example 1:
TEACHERS Table:

IDNAMEAGESUBJECT
1Jim27English
2John30Geology
3Watson28French
4Holmes40Chemistry
5Tony35Physics
SELECT * FROM TEACHERS 
ORDER BY NAME ASC;

Output:

IDNAMEAGESUBJECT
1Jim27English
2John30Geology
5Tony35Physics
3Watson28French

Explanation:
In the above example, all the records from the TEACHERS table after fetching are sorted in ascending order based on the NAME column.

Example 2:
TEACHERS Table:

IDNAMEAGESUBJECT
1Jim27English
2John30Geology
3Watson28French
4Holmes40Chemistry
5Tony35Physics
SELECT * FROM TEACHERS 
WHERE ID > 2
ORDER BY SUBJECT DESC;

Output:

IDNAMEAGESUBJECT
5Tony35Physics
3Watson28French
4Holmes40Chemistry

Explanation:
In the above example, all the records from the TEACHERS table where ID is greater than 2, are fetched first and are then sorted in descending order based on the SUBJECT column.

Please Share