开发者

MySQL Fulltext search where category = something

开发者 https://www.devze.com 2023-02-01 11:59 出处:网络
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:

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` 开发者_JAVA技巧) 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


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 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号