Mysql query in action query results display the _mysql_ script house in the In collection order

Source: Internet
Author: User

<title>Mysql query in action query results display the _mysql_ script house in the In collection order</title> MySQL Query in operation, the query results are displayed in the order of in collection
Copy CodeThe code is as follows:
SELECT * from test where ID in (3,1,5) Order by Find_in_set (ID, ' 3,1,5 ');
SELECT * from test where ID in (3,1,5) Order by Substring_index (' 3,1,2 ', id,1);


The occasional sight of ... Maybe someone would have noticed, but I didn't know it before.
Sql:select * FROM table where ID in (3,6,9,1,2,5,8,7);

After such a situation is taken out, in fact, the ID or by 1,2,3,4,5,6,7,8,9, sorted, but if we really want to press in the order of the inside of what to do? Can SQL be completed? Do you need to take it back and then foreach it? Actually, that's the way MySQL is.

Sql:select * FROM table where ID in (3,6,9,1,2,5,8,7) Order by field (id,3,6,9,1,2,5,8,7);

The order that comes out is the order of the specified .... This, before really never used, and occasionally see, so I recorded a bit. One is to make a note, and the other is to give more people a chance to see


From for notes (Wiz)

Mysql query in action query results display the _mysql_ script house in the In collection order

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.