SQLite's ORDER BY clause is used to sort data in ascending or descending order based on one or more columns.

Grammar

The basic syntax of the ORDER BY clause is as follows:

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

You can use multiple columns in the ORDER BY clause. Make sure the sort column you are using is in the column list.

Example

Assuming the COMPANY table has the following records:

# ID name Age Address Salar
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------- ----------- ---------- ----------
1 " Paul " 32 " California 20000.0
2 " Allen 25 Texas 15000.0
3 Teddy 23 NORWAY 20000.0 ## 4 Mark 25 Rich-Mond 65000.0
5 David 27 TEXAS 85000.0
6 KIM 22 South-Hall 45000.0
7 Jamest On 10000.0
The following is an example, which will sort the results in SALARY ascending order:

##sqlite> SELECT * FROM COMPANY ORDER BY SALARY ASC;

This will produce the following results:

ID                                                                                                                                                                                                         ------ ---------- ----------
7 James 24 Houston 10000.0
2 Allen 25 Texas 15000.0
1 Paul 32 California 20000.0
3 Teddy 23 Norway 20000.0
6 Kim 22 South-Hall 45000.0
4 MARK 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
## This is an instance, It will sort the results by NAME and SALARY in ascending order:

sqlite> SELECT * FROM COMPANY ORDER BY NAME, SALARY ASC;

This will produce the following results:

ID                                                                                                                                                                                                         ------ ---------- ----------
2 Allen 25 Texas 15000.0
5 David 27 Texas 85000.0
7 James 24 Houston 10000.0
6 Kim 22 South-Hall 45000.0
4 Mark 25 Rich-Mond 65000.0
1 Paul                                                                                                          It will sort the results in descending order by NAME:

##sqlite> SELECT * FROM COMPANY ORDER BY NAME DESC;

This will produce the following results:

ID                                                                                                                                                                                                         ------ ---------- ----------
3                                                                                  Teddy                                                          out   Mark 25 Rich- Mond 65000.0
6 Kim 22 South-Hall 45000.0
7 James 24 Houston 10000.0
5 David 27 Texas 85000.0
2 Allen 25 Texas 15000.0



Hot AI Tools
Undress AI Tool
Undress AI Tool

Undress images for free

AI Clothes Remover
AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress
Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT
ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT
Stock Market GPT

AI powered investment research for smarter decisions

Popular tool
Notepad++7.3.1
Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version
SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1
Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6
Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version
SublimeText3 Mac version

God-level code editing software (SublimeText3)