Two-Point usage of Mysql string function FIND_IN_SET ()

Source: Internet
Author: User

Two-Point usage of Mysql string function FIND_IN_SET ()

Summary: You can query fields separated by commas and forcibly sort the results.

First, let's look at a table:

Colid Vyear Area Cast
, 31,32, 21,12 2014 1 15
, 32, 33, 34, 35, 21, 2014 2 16
, 40 2011 3 17

The values of the colid field in the table are separated by commas,

When we need to query this table, the colid contains 32 rows,

You can use FIND_IN_SET ()

The SQL statement is as follows:

SELECT * FROM table WHERE FIND_IN_SET ('32', colid );
The following can be written for forced sorting:
SELECT * FROMtableWHEREarea IN (2, 1, 3) order by find_in_set (area, '2, 3, 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.