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 sid开发者_如何学运维ebar. 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?
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
select.....
where find_in_set(current article name,name of column)
try this
精彩评论