search

Home  >  Q&A  >  body text

mysql - PHP database query questions

There is an article table, and there is a field associated with tags in the article table tag
tag The content of the field is basically like this: 1,2,3,333,230 ( Associated tag IDs, separated by commas)
Now there is a problem. I now want to find the article with tag ID 3. Using LIKE %3% seems to find out the contents of 333,230 tags
No change In the case of table structure, is there any query method?

过去多啦不再A梦过去多啦不再A梦2796 days ago463

reply all(5)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:09:48

    SELECT * FROM test WHERE find_in_set('3',tag)

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:09:48

    tag LIKE '%,3' or tag LIKE '3,%' or tag LIKE '%,3,%'

    reply
    0
  • 高洛峰

    高洛峰2017-05-16 13:09:48

    LIKE %,3,% just add a comma

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-16 13:09:48

    find_in_set, use this to meet your requirements, don’t use like....

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-16 13:09:48

    I recommend using another table to maintain the classification relationship. find_in_set is a full table scan without using indexes. There will be problems with the database by then

    reply
    0
  • Cancelreply