Home >Database >Mysql Tutorial >How to Prioritize MySQL Table Rows by Rating and Date?
Prioritizing Rows in a MySQL Table: Sorting by Multiple Columns
You wish to organize your MySQL table by two criteria: highest ratings and most recent dates. To achieve this, you need to implement multi-column sorting.
Originally, you employed the following SQL statement:
ORDER BY article_rating, article_time DESC
However, this approach only sorted by a single column (article_rating). To sort by two columns, your query requires modifications.
Solution:
By default, sorting is performed in ascending order. To induce descending order for both columns, append the keyword "DESC" after each.
Here's the revised query:
ORDER BY article_rating DESC, article_time DESC
This modification ensures that the data is ordered first by article_rating (highest to lowest), and within that ranking, the articles are sorted by article_time (most recent to least recent).
The above is the detailed content of How to Prioritize MySQL Table Rows by Rating and Date?. For more information, please follow other related articles on the PHP Chinese website!