Detailed explanation of the order of Mysql query results according to the order of ID in in()

Detailed explanation of the order of Mysql query results according to the order of ID in in()

Detailed explanation of the order of Mysql query results according to the order of ID in in()

Example code:

<select id="queryGBStyleByIDs" resultMap="styleMap"> 
    select style_num_id ,style_id,style_title,style_pic FROM gb_style where online = 1 AND is_hide = 0 and style_num_id in 
    <foreach collection="styleNumIDs" item="styleNumId" separator="," open="(" close=")"> 
     #{styleNumId} 
    </foreach> 
    ORDER BY FIELD 
    <foreach collection="styleNumIDs" item="styleNumId" separator="," open="(style_num_id," close=")"> 
      #{styleNumId} 
    </foreach> 
  </select> 

The final output sql is as follows:

select style_num_id ,style_id,style_title,style_pic FROM gb_style where online = 1 AND is_hide = 0 and style_num_id in (1,3,2,5) 
order by field (style_num_id,1,3,2,5);

If you have any questions, please leave a message or come to the community to discuss. Thank you for reading and I hope it can help you. Thank you for your support of this site!

You may also be interested in:
  • MySQL query in operation query results are displayed in the order of in set
  • Solve the problem that IN subquery in MySQL will cause the index to be unusable
  • Examples of optimization techniques for slow query efficiency in MySQL IN statements
  • Comparison of the efficiency of using or, in and union all in MySQL query commands
  • Mysql subquery IN using LIMIT application example
  • Will the index be used in the MySQL query condition?
  • A brief discussion on the efficiency of MySQL subquery union and in
  • Implementation of MySQL select in subquery optimization
  • MySQL SQL Optimization Tutorial: IN and RANGE Queries

<<:  One question to understand multiple parameters of sort command in Linux

>>:  Detailed explanation of CocosCreator message distribution mechanism

Recommend

MySQL select results to perform update example tutorial

1. Single table query -> update UPDATE table_n...

Installation and configuration of mysql 8.0.15 under Centos7

This article shares with you the installation and...

GET POST Differences

1. Get is used to obtain data from the server, wh...

HTML6 implements folding menu and accordion menu example code

The main part of the page: <body> <ul id...

Detailed steps to build an NFS file sharing server in Linux

Linux builds NFS server In order to achieve data ...

Web design reference firefox default style

Although W3C has established some standards for HT...

WeChat applet implements fixed header and list table components

Table of contents need: Function Points Rendering...

Vue+SSM realizes the preview effect of picture upload

The current requirement is: there is a file uploa...

Nginx http health check configuration process analysis

Passive Check With passive health checks, NGINX a...

Detailed explanation of cross-usage of Ref in React

Table of contents 1. First, let’s explain what Re...

A brief discussion on several ways to pass parameters in react routing

The first parameter passing method is dynamic rou...

Suggestions on creating business HTML emails

Through permission-based email marketing, not onl...

MySQL 8.0.20 installation and configuration detailed tutorial

This article shares with you a detailed tutorial ...

How to build Nginx image server with Docker

Preface In general development, images are upload...