Home > Database > Mysql Tutorial > How to Prioritize MySQL Table Rows by Rating and Date?

How to Prioritize MySQL Table Rows by Rating and Date?

Mary-Kate Olsen
Release: 2024-12-06 16:51:18
Original
1065 people have browsed it

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template