Mysql searches for multiple fields
In mysql, If You Want To sort a field, you can use the following SQL statement
SELECT * FROM 'table _ name' order by 'field'
However, what should I do if I want to sort a field and then another field? You can use the following SQL statement
SELECT * FROM 'table _ name' order by FIELD1, FIELD2;
If you want to add sorting
SELECT * FROM 'table _ NAME; order by FIELD1 DESC, FIELD2;
Implementation of the pin function
The following is an example of sorting two fields.
I believe you have seen top posts in BBS and you have used the top posts step. Have you ever thought about how to implement the top posts function?
To implement this function in a project, I add a field in the database to identify the weight of the post, and the row with a high weight will appear, if the weights are equal, they are sorted by time. In this way, the pin function is implemented.
SELECT * FROM 'table _ name' order by piority desc, data desc;