我需要这个查询来选择category=logotypes和完整文本与searchword相似的所有文章,就像它已经这样做了。

SELECT      *
FROM        posts
WHERE       category = :logotypes
AND         full_text LIKE CONCAT('%', :term, '%')
ORDER BY    post_date DESC

但我希望搜索词也检查标题中是否有匹配项,如:
    SELECT      *
    FROM        posts
    WHERE       category = :logotypes
    AND         full_text LIKE CONCAT('%', :term, '%')
--> ALSO CHECK  heading LIKE CONCAT('%', :term, '%')
    ORDER BY    post_date DESC

我该怎么办?
请注意,这一类别应始终保持不变。必须仍然category = :logotypes

最佳答案

简单地用ALSO CHECK替换OR

SELECT      *
FROM        posts
WHERE       category = :logotypes
AND        (full_text LIKE CONCAT('%', :term, '%')
OR          heading LIKE CONCAT('%', :term, '%'))
ORDER BY    post_date DESC

观察OR连接谓词周围的括号

关于mysql - SQL Select 2类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12074408/

10-10 10:23