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. Thanks
views:
28answers:
1
A:
Do 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.
Tom Bartel
2010-02-02 09:03:02