Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql how in query operations are sorted

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will introduce in detail for you "mysql how in query operations sort", the content steps are clear and detailed, the details are handled properly, and the editor will update different knowledge points every day, hope that this article "mysql how in query operations sort" can give you unexpected harvest, please follow the editor's ideas slowly in depth, the specific content is as follows, to harvest new knowledge.

In mysql, you can use the "ORDER BY" clause with the SELECT statement in query to operate sorting. The syntax is "select*from table name where field value in (sort 1, sort 2...) order by field (field value, sort 1, sort 2...);".

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

Mysql how in query operations are sorted

Let's start with the solution:

Select * from test where id in (3, 1, 5) order by field (id,3,1,5)

Maybe someone will notice.

SQL: select * from table where id IN (3, 6, 9, 1, 2, 5, 8, 7)

After such a situation is taken out, in fact, id is still sorted according to 1, 2, 3, 4, 5, 6, 7, 8, 9.

But what if we really want to sort it in the order in IN? Can SQL finish it?

Do you need to foreach it after you get it back? In fact, mysql has this method.

Field function.

Function format: order by field (str,str1,str2,str3...)

Str is a field, and str1\ str2\ str3 is a specific column value

Sql: select * from table where id IN: order by field (id,3,6,9,1,2,5,8,7); thank you for reading this. I hope you have the most profound understanding of the key question of "how to sort in query operations in mysql" from the practical level, and the specific usage needs to be understood by yourself. if you want to read more related articles, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report