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
Table of contents JSON.parse JSON.parse Syntax re...
1. What is master-slave replication? The DDL and ...
In cells, light border colors can be defined indi...
This article mainly introduces the Mysql backup m...
This article is a self-written imitation of the X...
Some of you may have heard that the order of trav...
1. Always close HTML tags In the source code of p...
Side note <br />If you know nothing about HT...
Table of contents 1. Select All 2. Increase or de...
Table of contents 1. Command 2. docker-compose.ym...
1. Check the PHP version after entering the termi...
Preface: rm under Linux system is irreversible. T...
Using padding-top percentage can achieve a fixed ...
1. ROW_NUMBER() Definition: The ROW_NUMBER() func...
Table of contents background example Misconceptio...