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
Table of contents 1. Introduce according to the o...
Record the installation and configuration method ...
Select or create a subscription message template ...
Preface MySQL supports many types of tables (i.e....
HTML meta tag HTML meta tags can be used to provi...
Table of contents 1. The elephant that can’t fit ...
1. Create a new virtual machine in VMware 15.5 1....
Table of contents Add Configuration json configur...
Problem description (what is keep-alive) keep-ali...
Table of contents 1. v-text text rendering instru...
CSS Styles html,body{ width: 100%; height: 100%; ...
Installation Steps 1. Install Redis Download the ...
1. Environmental requirements 1. Docker 17 and ab...
Use regular expressions to determine the IE browse...
This article example shares the specific code of ...