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:
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:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------- ----------- ---------- ----------
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
This will produce the following results:
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 will produce the following results:
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:
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 images for free
Online AI tool for removing clothes from photos.
AI-powered app for creating realistic nude photos
AI image generator for creative art from text prompts.
AI powered investment research for smarter decisions
Hot Article
Hot Topics
20450
7
13593
4
Popular tool
Easy-to-use and free code editor
Chinese version, very easy to use
Powerful PHP integrated development environment
Visual web development tools
God-level code editing software (SublimeText3)












![Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]](https://img.php.cn/upload/course/000/000/035/5d27fb58823dc974.jpg)