开发者

SQL find rows whose column "tag" contains a tag

开发者 https://www.devze.com 2023-01-08 02:12 出处:网络
I have a table for articles. Its major fields are: id article_name content tags (its values will be comma seperate example test, abc ...)

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

精彩评论

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