SQLite ORDER BY condition is utilized to sort the information in a rising or dropping request, in view of at least one sections.
Syntax
Following is the essential language structure of ORDER BY statement.
SELECT column-list
FROM table_name
[WHERE condition]
[ORDER BY column1, column2, .. columnN] [ASC | DESC];
You can utilize more than one section in the ORDER BY statement. Ensure whatever section you are utilizing to sort, that segment ought to be accessible in the segment list.
Example
Consider COMPANY table with the accompanying 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
Following is a model, which will sort the outcome in diving request by SALARY.
sqlite> SELECT * FROM COMPANY ORDER BY SALARY ASC;
This will create the accompanying outcome.
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
Following is a model, which will sort the outcome in diving request by NAME and SALARY.
sqlite> SELECT * FROM COMPANY ORDER BY NAME, SALARY ASC;
This will deliver the accompanying outcome.
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
Following is a model, which will sort the outcome in dropping request by NAME.
sqlite> SELECT * FROM COMPANY ORDER BY NAME DESC;
This will deliver the accompanying outcome.
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