This article introduces a tutorial about how to use the find_in_set() function to sort by the order in where in () in MySQL. I hope this tutorial can be helpful to you. select * from table where id in ('783',' 769',' 814',' 1577',' 1769') order by find_in_set( id, '783, 769, 814, 1577, 1769' ) Check out: 769 1577 814 1769 783 Why not the order 783 769 814 1577 1769? Note: After searching, it was found that the cause was in find_in_set. If there is a space in the second parameter of find_in_set, the order will be messed up, because MySQL will not trim the space character for you before querying. so... After removing spaces: select * from table where id in ('783',' 769',' 814',' 1577',' 1769') order by find_in_set( id, '783,769,814,1577,1769' ) Note that it is just removed Check it out again: 783 769 814 1577 1769 So far, we have implemented the sorting using where in find_in_set. find_in_set can also implement multi-condition sorting. Summarize The above is all about how MySQL uses the find_in_set() function to implement where in() order sorting. Interested friends can refer to: MySQL database table partitioning precautions [recommended], several important MySQL variables, sql and MySQL statement execution order analysis, etc. If there are any deficiencies, you are welcome to leave a message to correct them. I hope this helps you all. You may also be interested in:
|
<<: Install Memcached and PHP Memcached extension under CentOS
>>: How to build a drag and drop plugin using vue custom directives
The HTTP request methods specified by the HTTP/1....
This article example shares the specific implemen...
Later, I also added how to use Jupyter Notebook i...
Table of contents Preface Introduction to QueryCa...
Problem/failure/scenario/requirement The hard dis...
Table of contents Preface 1. Error log 2. Binary ...
1. Overview of modules and instructions used to l...
Preface At work, I need to count the materials su...
Detailed installation tutorial of mysql-5.7.23-wi...
Flex layout is undoubtedly simple and easy to use...
1. Install openssh-server yum install -y openssl ...
Table of contents 1. Introduction 2. Introduction...
<a href="https://www.jb51.net/" titl...
<META http-equiv="Page-Enter" CONTENT...
Table of contents 1. Introduction to NFS-Ganesha ...