The use of the MySQL find_in_set () query function

Source: Internet
Author: User

Table tables are structured as follows:

ID title
1 12,21
2 21,32
3 45,21,78
4 221,45,74
5 34,421,121
6 52,21,321

Now what do I do with the SQL statement to find out all the records in the field that contain 21?

SELECT * FROM table where title=21 or the title like '%,21 ' or the title like '%,21,% ' or the title like ' 21,% '

Do you see any problems with this view?

I'm sure this will find out 421, 221 of this information!

Now use this find_in_set function to check

SELECT * FROM table where Find_in_set (' + ', title);

This is to find out, id 1, 2, 3, 6 and so on four piece of information!

Of course, you can also set the title field to-x-x-x-such as the format, through like query%-x-% also line

The use of the MySQL find_in_set () query function

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.