
Consider we have another table named agents with the following records: AID DESC keyword will sort the records in descending order.Īll the records present in the customers table are displayed in the descending order of the customer's age. Here in a SELECT query, an ORDER BY clause is applied on the column 'Age' to sort the records. Mysql> SELECT *FROM customers ORDER BY Age DESC
Syntax to sort the records in ascending order:
If no keyword is specified after the column based on which we have to sort the records, in that case, the sorting will be done by default in the ascending order.īefore writing the queries for sorting the records, let us understand the syntax. DESC keyword will sort the records in descending order. The records will be sorted in ascending order whenever the ASC keyword is used with ORDER by clause.
Using the ORDER BY clause, we can sort the records in ascending or descending order as per our requirement. This means that all the values stored in the column on which we are applying ORDER BY clause will be sorted, and the corresponding column values will be displayed in the sequence in which we have obtained the values in the earlier step. The ORDER BY clause in SQL will help us to sort the records based on the specific column of a table. Whenever we want to sort the records based on the columns stored in the tables of the SQL database, then we consider using the ORDER BY clause in SQL. What ever you "Order by" here is used verbatim and not affected by any GSAK settings (like special sort sequence for "name"). Note: SQLSort is just a portal to the SQLite "Order by" clause and is not aware of any GSAK settings. # Now finally restore our current sort sequence
SQLSort OrderBy=Terrain Asc, Difficulty desc #Change our sort sequence to do some work in our desired sequence Using the $_OrderBy system variable, also makes it quite easy to save and restore your current grid sort sequence
SQLSort OrderBy=Difficulty, Distance desc
#SQLITE ORDER BY ASC AND DESC CODE#
To sort by ascending by difficulty then descending by distance the code would be: For example to sort the grid in sequence of the longest hint first to the smallest hint the code would simply be: Not only can you sort ascending/descending by multiple columns but you can use functions as well. Any valid SQLite "order by" clause for the caches table can by used to order the grid. This command will allow you to change the sort order of the grid.