mysql - PHP database query questions
过去多啦不再A梦
过去多啦不再A梦 2017-05-16 13:07:48
0
5
460

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梦

reply all(5)
给我你的怀抱

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

Ty80
tag LIKE '%,3' or tag LIKE '3,%' or tag LIKE '%,3,%'
小葫芦

LIKE %,3,% just add a comma

Peter_Zhu

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

漂亮男人

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template