How to show related content using like in mysql?
I currently have a table for products with it's own set of tags and a table for news with it's own set of tags. I wanted to add related news to the products page so I was thinking of using like but since the column tags开发者_如何转开发 in the products page is something like
(Products) tags- manutd, man utd, football (news) tags - manutd, blah, bruha [this one is related] (news) tags - man, utd, bruha [this one is not related] I wanted to use a query to show all news containing any of the tags(from products) seperated by commas using mysql. How should I go about constructing such a query? If there is a better way of doing this a little explanation would be helpful too. ThanksDo you have the product tags at hand or do you want to join the two tables based on their tag similarity? In the first case, I would try something like this:
select ...
from News n
where n.tags REGEXP 'manutd|man utd|football'
Note that I used the product tag string you provided above, replaced the commas by |
and removed the whitespace to the left and right of the commas.
精彩评论