Home  >  Q&A  >  body text

Is there any way in Mysql to query a string inside another string?

Mysql Is there any way to query? For example, the string '3,5' is within the string '3,4,5,2'

The situation is probably like this

How many users are there? An attribute, the attribute ID is stored in a field in the user table

For example, user_attr, the value storage format is: '3,4,5,2',

Explanation: For example, numbers are attributes ID

Now the front end needs to query �%9

ECHOECHO1776 days ago990

reply all(5)I'll reply

  • 孤独是一种态度

    孤独是一种态度2020-03-18 09:19:54

    find_in_set() Learn more

    reply
    0
  • lk

    lk2020-01-15 18:29:13

    like correct answer

    reply
    0
  • junwind

    junwind2020-01-14 17:12:31

    There is no need to use sql query here. Convert 3,5 passed from the front end into array [3,5], and then 3,4,5,2 are also converted into arrays. Compare them to know whether they are in it.

    reply
    0
  • null

    null2020-01-03 00:31:25

    Convert 3 and 5 into arrays, loop and splice where conditions, user_attr like '%3%' or user_attr like '%5%' groug by user id? Maybe the efficiency is not that high, it can be achieved

    reply
    0
  • ECHO

    If you use like, you can’t tell the difference between 3,13 5,15.

    ECHO · 2020-01-04 16:00:36
  • Cancelreply