Home > Database > Mysql Tutorial > body text

Example analysis of Mysql query results arranged in the order of ID in in()

黄舟
Release: 2017-09-26 10:29:05
Original
2143 people have browsed it

This article mainly introduces the relevant information that explains in detail the order of Mysql query results in the order of ID in in(). I hope this article can help everyone. Friends in need can refer to it

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

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

The above is the detailed content of Example analysis of Mysql query results arranged in the order of ID in in(). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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