Multiple values of a field are separated by commas (,) to retrieve all IDs of a field containing a specific value in the data table.

Source: Internet
Author: User
Example: {code ...} take out the user_id with 2 IDs. the result 1, 2 (containing separate 2) like method obviously does not work. The simple and beautiful SQL statement shows that the field structure is greatly changed downstairs, this is not allowed currently. Because the entire project is successful, if I am using this one:

id   user_id   1    2,32,42    3,63,23    4,62,7 

Retrieveuser_idIn2Ofid, Result = "1, 2 (contains separate 2)

  1. The like method obviously does not work.

  2. Simple and beautiful SQL statements

  3. We can see that there isLargeIt is not allowed to change the field structure. This is because the entire project is accessible. if I change the field structure when I call it elsewhere, unpredictable problems may occur.

Reply content:

Example:

id   user_id   1    2,32,42    3,63,23    4,62,7 

Retrieveuser_idIn2Ofid, Result = "1, 2 (contains separate 2)

  1. The like method obviously does not work.

  2. Simple and beautiful SQL statements

  3. We can see that there isLargeIt is not allowed to change the field structure. This is because the entire project is accessible. if I change the field structure when I call it elsewhere, unpredictable problems may occur.

SELECT id FROM table WHERE find_in_set('2',user_id);

Id user_id
1, 2, 32, 4,
2, 3, 63, 2,
3, 4, 62, 7,

If this is the case, you can do like.

In fact, it is better to split the intermediate table.

Table product

id      1    2   3    

Table user

user_id   234632   6263    

Intermediate table

product_id   user_id1               21               321               42               22               632               33               43               623               7

We recommend that you change the table structure! This is really hard to get. Or change the data storage method as shown in figure

id   user_id   1    [2],[32],[4]2    [3],[63],[2]3    [4],[62],[7]

In this way, you can use fuzzy search. However, it is recommended that you modify table data.

Json type obtained by mysql5.7

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.