How does Mysql search to determine whether a field contains a string?

Source: Internet
Author: User

To meet this requirement, in the Mysql database string field (permission), the user has multiple mailboxes separated by commas (,). Now, you need to retrieve the list of all members of a mailbox.

Suppose there is a table:

 

Users (id () AUTO_INCREMENT, (id), (), emails ());

Initialize the table and add some records.

Users (, emails) (, users (, emails )(,);

In Mysql, some fields are of the string type. How do I find records containing some characters?

Method 1

It is easy to implement with %.

For example

Users emails "B .com ";

But this will be the bb@email.com also found out does not meet the needs of

Method 2

Use the mysql string function find_in_set ();

Users find_in_set (, emails );

In this way, you can find all the users with aa@emial.com in the e-mail field.

In this way, we can achieve the expected results and solve the problem!

Note that: Mysql string function find_in_set (str1, str2) returns the index of the position of str1 in str2. str2 must be separated by commas.

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.