Problem Description As we all know, the SQL to sort in ascending order by a field in MySQL is (taking id as an example, the same below): SELECT * FROM `MyTable` The SQL for descending order is: SELECT * FROM `MyTable` Sometimes the above sorting does not meet our needs. For example, we want to sort by id in the order of 5, 3, 7, 1, how to achieve it? This is also one of the problems often encountered by many domestic and foreign counterparts. Below we give a solution to sort a field in the table in the list format we want. Solution Use "ORDER BY FIELD". grammar ORDER BY FIELD(`id`, 5, 3, 7, 1) Note that there is no space after FIELD. Therefore, the complete SQL is: SELECT * FROM `MyTable` Common Applications SELECT * FROM `MyTable` The above article on how to implement MySQL custom list sorting by specified fields is all I want to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of Vite's new experience
>>: How to use vite to build vue3 application
You need to add "gt_" in front of the f...
This article is used to record the installation o...
1. Shut down the mysql service # service mysqld s...
Web page design related questions, see if you can...
Preface: It’s the end of the year, isn’t it time ...
1. DNS server concept Communication on the Intern...
ERROR 1290 (HY000) : The MySQL server is running ...
1. Download MySQL Official website download addre...
This article example shares the specific code of ...
Prerequisites A cloud server (centOS of Alibaba C...
Table of contents Foreign Key How to determine ta...
Notice! ! ! This situation can actually be avoide...
1. How to construct? Let's review the common ...
As we all know, without the cd command, we cannot...
Basic introduction to robots.txt Robots.txt is a p...