MySQL find_in_set (str,strlist) function use (in according to the ID of the inside sort)

Source: Internet
Author: User

bloggers have encountered such a problem in development:  select * from ' user ' Whereid in (23,1,55,94)when executing a SQL similar to this one, MySQL will sort the IDs in advance and then look for them: Description: This is introduced in high-performance MySQL, in the query is actually a process of sweeping the table, in the query, the bottom is the ID in the inside of the first order from small to large optimization, and then execute in query, soIt 's a good idea to manually sort the IDs from small to large and then execute in queries, such as in (1,23,55,94), and then sort them in the order you want . But the business requires that the query results be returned in the order of the in ID (that is, the order of 23,1,55,23,94), what should be done? This statement can be done, is not very convenient: select * from ' user ' where Find_in_set (ID, ' 23,1,55,94 ')  Off -topic: There is a non-recommended but feasible way, is to get the ID of the array after the traversal of the separate library, which will certainly affect a lot of performance ...

MySQL find_in_set (str,strlist) function use (in according to the ID of the inside sort)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.