SQLite’s ORDER BY Clause is used to sort data in ascending or descending order based on one or more columns. You can find it in the Hypothetical Here is an example that presses the result This will produce the following results: Here is an example that presses the result This will produce the following results: Here is an example that presses the result This will produce the following results: 1.23.1. Grammar ¶
ORDER
BY
The basic syntax of the clause is as follows:SELECT column-list
FROM table_name
[WHERE condition]
[ORDER BY column1, column2, .. columnN] [ASC | DESC];
ORDER
BY
Multiple columns are used in the clause. Make sure that the sort you use is listed in the list. 1.23.2. Example ¶
COMPANY
The table has the following records:ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
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 James 24 Houston 10000.0
SALARY
Sort in ascending order:sqlite> SELECT * FROM COMPANY ORDER BY SALARY ASC;
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
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
NAME
And
SALARY
Sort in ascending order:sqlite> SELECT * FROM COMPANY ORDER BY NAME, SALARY ASC;
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
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 32 California 20000.0
3 Teddy 23 Norway 20000.0
NAME
Sort in descending order:sqlite> SELECT * FROM COMPANY ORDER BY NAME DESC;
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
3 Teddy 23 Norway 20000.0
1 Paul 32 California 20000.0
4 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