MySQL string function find_in_set () Two-point usage

Source: Internet
Author: User

Summary: You can query the fields separated by commas and force the sorting of the results.

First look at a table:

Area
colid Vyear cast
, 31,32,21,12 2014 1 15
, 32,33,34,35,21, 2014 2 16
, 33,34,36,39,40 2011 3 17

The value of the Colid field in the table is separated by commas,

When we need to query this table, Colid contains 32 rows,

Then you can use Find_in_set ()

SQL is as follows:

SELECT * FROM table WHERE find_in_set (' + ', colid);

A forced sort can be written like this:

Select*fromtablewherearea in (2,1,3) ORDER         by Find_in_set (area, ' 2,1,3 ');


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.