MySQL is ordered by the order in the in statement.

Source: Internet
Author: User

In SQL, we sometimes use in the query statement to query related data. For example:

  1. Select * from goods where goods_id in ('20160301', '64', '20160301', '37', '20160301', '20160301', '20160301 ', '123', '123', '123', '123 ')

In the preceding query, the returned results are sorted from small to large in the order of good_id, that is, 222 ....

The expected return sequence is: '123', '64', '123', '37', '123', '123', '123', '123', '123 ', '123', '123', '123', '123'

Use the following statement:

  1. Select * from goods where goods_id in ('20160301', '64', '20160301', '37', '20160301', '20160301', '20160301 ', '123', '123', '123', '123') Order
    By field (goods_id, '123', '64', '123', '37', '123', '123', '123', '123', '123 ', '123', '123', '123', '123 ')

 

The keyword field is followed by the field name goods_id to be sorted.

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.