In a normalized database the tags would have their own (link-)table.
It depends on how you want to retrieve your data. It is possible to build a query in code that will return your result. Doing it in a single query would be very difficult. For a single category you can use FIND_IN_SET(). Checking more categories would require you to build a query consisting of more FIND_IN_SET()'s.
SELECT * FROM table WHERE FIND_IN_SET('action', categorycolumn)
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
You would have to create a query similar to this one:
SELECT * FROM table WHERE
FIND_IN_SET('action', categorycolumn) AND
FIND_IN_SET('fantasy', categorycolumn)
UNION
SELECT * FROM table WHERE
FIND_IN_SET('action', categorycolumn) AND
NOT FIND_IN_SET('fantasy', categorycolumn)
UNION
SELECT * FROM table WHERE
FIND_IN_SET('fantasy', categorycolumn) AND
NOT FIND_IN_SET('action', categorycolumn)
You can imagine it gets worse when the number of tags increase.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
I think you can create a query like this:
SELECT * FROM linktable WHERE category IN ('action', 'fantasy')
GROUP BY movie
ORDER BY COUNT(1) DESC,movie
The order by puts the movies with the most category hits on top.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
The SELECT gets everything that has at least one of your specified categories. Then you group it by movie, so you can count how many records you found for that movie (the matching categories). The minimum will be 1, the maximum the number of categories in the IN clause. The order by puts the one with the most hits on top. If they are the same it orders them by title (in my imaginary table at least).
Thanks for the kudos, but I only know this because I've used it before. I'm more a grunt than a god.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
No problem. Please mark this thread solved.
pritaeas
Posting Expert
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875