I'm trying to write a custom search that will search "all categories" and individual categories (via a form/select dropdown). I'm having problems with my individual category search. When I test my sql, it returns good results, but I'm getting extra/unwanted categories in my results. I'm getting those extra categories in my results due to my AND and OR clauses.
For example, in my test query for "vector" I'm getting results from 3 categories because the word "vector" appears in titles, descriptions, or tags in 3 separate categories. What I want to do is restrict that to only showing the appropriate section (which is chosen from the form/select dropdown). So for example, I'm getting results from category 8, 12 and 13, but I only want to show category 8 (because that's what I'm selecting in my form/dropdown - that's my WHERE clause below).
My results make total sense, but I'm not sure how to only show only results from category 8 (in my test example). I basically want to do some further filtering to reduce the result set to only category 8.
SELECT title,category
FROM stories
WHERE category=8
AND title LIKE '%vector%'
OR desc LIKE '%vector%' OR tags LIKE '%vector%'
ORDER BY time DESC