'SQL find rows whose column "tag" contains a tag
I have a table for articles. Its major fields are:
id
article_name
content
tags (its values will be comma seperate example test, abc ...)
Now when I am on a detail page of any article. I want to show related article in my sidebar. For this if any other article uses the same tag as current article. I want to list those articles as related article. This is my query.
Can anyone please help me on this issue?
Solution 1:[1]
For minimum coding you can use FIND_IN_SET function.
SELECT FIND_IN_SET('b','a,b,c,d');
But next time consider using an additional table to store each tag in separate record
Solution 2:[2]
select.....
where find_in_set(current article name,name of column)
try this
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Naktibalda |
| Solution 2 | Thor |
