Query Result sequence of mysqlin

Source: Internet
Author: User
MySQL queries the in operation. The query results are displayed in the in set order: select * fromtestwhereidin (, 5) orderbyfind_in_set (id, 5); occasionally seen... Some people may have noticed this, but I have never known SQL: select * fromtablewhereidIN (,);

MySQL queries the in operation. The query results are displayed in the in set order: select * from test where id in (, 5) order by find_in_set (id, '3 '); occasionally seen... Some people may have noticed this, but I have never known SQL: select * from table where id IN (,);

MySQL queries the in operation. The query results are displayed in the in set order:

Select * from test where id in (3, 1, 5) order by find_in_set (id, '3, 1, 5 ');

Occasionally seen... Some people may have noticed it, but I did not know it before.
SQL: select * from table where id IN (3, 6, 9, 1, 2, 5, 8, 7 );

After such a situation is obtained, the IDs are actually sorted by 1, 2, 3, 4, 5, 6, 7, 8, 9, but what if we really want to sort IN order? Can SQL be completed? Do you need to get it back before foreach? In fact, mysql has this method.

SQL: select * from table where id IN (,) order by field (id );

The order is the specified order.

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.