Home >Database >Mysql Tutorial >How to sort in a specific order in mysql
Mysql queries IN and sorts it in a specific order
When performing data query operations, sometimes we sort it in a specific order.
Suddenly seen on the Internet To a sorting method, record it for later use:
Normal in query
select * from score where id in(3,1,5);
We can see that the data is It came out, but it is not in the order we need.
So how to query so that the found data can be in the order of (3,1,5)?
Specific order sorting (field)
select * from score where id in(3,1,5) order by field(id,3,1,5);
The order found in this way is what we want.
Recommended learning: "mysql video tutorial"
The above is the detailed content of How to sort in a specific order in mysql. For more information, please follow other related articles on the PHP Chinese website!