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
1.1. Download: Download the zip package from the ...
Yesterday, I helped someone install a system and ...
Three tables are connected. Field a of table A co...
Currently, almost all large websites and applicat...
1. Flex is the abbreviation of Flexible Box, whic...
1. The window size opened by the HTML hyperlink C...
1. Introduction By enabling the slow query log, M...
Call How to call Amap API? The official open docu...
This article uses an example to describe how to c...
Firefox, Opera and other browsers do not support W...
Table of contents Scene Introduction Deep respons...
MySQL deduplication methods 【Beginner】There are v...
1. Basic steps 1: Install yarn add vue-i18n Creat...
Table of contents 1. VueRouter 1. Description 2. ...
background: Tablespace: All INNODB data is stored...