开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜