Mike L.
Mike L.

Reputation: 1966

MySQL Fulltext search where category = something

This is driving me crazy, I have searched everywhere and can not seem to find an example. I am doing a fulltext MySQL search like so:


SELECT *
FROM `posts`
WHERE MATCH (
`title` , `description` , `location`
)
AGAINST (
'SEARCH TERM'
IN BOOLEAN
MODE
)
ORDER BY `id` DESC
LIMIT 0 , 100

that works fine but I have another column in my table "category" and would like to return results only from that category something like:

SELECT * FROM `posts` WHERE MATCH ( `title` , `description` , `location` ) AGAINST ( 'fayetteville' IN BOOLEAN MODE ) WHERE `category` = 'SEARCH CATEGORY' ORDER BY `id` DESC LIMIT 0 , 100

of course that second bit of code does not work, but how can I do this in MySQL?

Thanks

Upvotes: 2

Views: 437

Answers (1)

Mark Byers
Mark Byers

Reputation: 838156

You can only have one WHERE clause. Change your second WHERE to AND.

SELECT *
FROM `posts`
WHERE MATCH ( `title` , `description` , `location` )
      AGAINST ( 'fayetteville' IN BOOLEAN MODE )
AND `category` = 'SEARCH CATEGORY'
ORDER BY `id`
DESC LIMIT 0 , 100 

Upvotes: 2

Related Questions