Home > Database > Mysql Tutorial > body text

How to sort in a specific order in mysql

藏色散人
Release: 2021-09-09 15:28:09
forward
4139 people have browsed it

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);
Copy after login

How to sort in a specific order in mysql

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);
Copy after login

How to sort in a specific order in mysql

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!

Related labels:
source:fengkui
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template