MySQL ORDER BY: Sort Query Results
In MySQL, you can use the ORDER BY clause to sort the query results. The ORDER BY clause can sort the results based on one or multiple columns, and you can also specify the order (ascending or descending).
Here is an example demonstrating how to use the ORDER BY clause to sort query results.
SELECT * FROM table_name ORDER BY column_name ASC/DESC;
In the example above, table_name is the name of the table to be queried, and column_name is the name of the column to be sorted by. ASC indicates sorting in ascending order, and DESC indicates sorting in descending order.
If you need to sort by multiple columns, you can specify multiple column names in the ORDER BY clause and sort them in the specified order. For example:
SELECT * FROM table_name ORDER BY column1 ASC, column2 DESC;
In the example above, firstly sort in ascending order based on column1, and then further sort in descending order based on column2.
Please note that if no sorting order is specified, the default method is to sort in ascending order.