2

我需要这个查询来选择 category = logotypes 和 full_text 就像搜索词一样的所有帖子。

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

我该怎么办?

PS该类别应始终保留。它仍然必须是category = :logotypes

4

2 回答 2

4

只需替换ALSO CHECKOR

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

OR观察-connected 谓词周围的括号

于 2012-08-22T13:38:01.163 回答
1
SELECT      * 
FROM        posts 
WHERE       category = :logotypes 
AND        
(
    full_text LIKE CONCAT('%', :term, '%') 
    OR 
    heading LIKE CONCAT('%', :term, '%')  
)
ORDER BY    post_date DESC 

或者,如果你觉得晦涩难懂

AND CONCAT(full_text,'/', heading) LIKE CONCAT('%', :term, '%')  
于 2012-08-22T13:38:10.960 回答