Good day, users! Help please compile the right MySQL query. My question is as follows: There is a table in which “tags” are stored and nothing more .. In another “News” table there is a “tags” field that contains IDs of tags I entered, for example, 1, 2, 4, 7.

I pass the tag to the function and I need to sort all the news with this tag.

I do not want to use in the table a selection of the field "tags" through WHERE LIKE "%%" . Can you help and suggest a good and correct alternative without the WHERE tags LIKE "%%" ?

  • one
    Redesign DB? Those. put the link "news tag" in a separate table. Recently, the responses saw a mention of mangoDB (?) - an alternative to relational databases. It seems as mentioned in a similar context. And if the task was to search by text - I would advise something like Sphinx, but in this context its use is unlikely to be justified. - BOPOH


1 answer 1

Made at the moment WITHOUT WHERE LIKE "%%" as follows. If something correct me, if anything is corrected, then it may be useful to someone ...

SELECT n.id, n.text, n.tags FROM tags t, news n WHERE t.name="нужный тег" AND FIND_IN_SET(t.id, n.tags) > 0