有谁知道为什么在此查询中忽略已发布的索引?
SELECT news.id, news.slug, news.title, news.created_on FROM (news)
WHERE `published` = '1'
AND news.title LIKE '%running%'
OR news.body LIKE '%running%'
OR news.intro LIKE '%running%'
ORDER BY created_on desc
答案 0 :(得分:6)
我会假设OR正在造成它。 在OR连接的三个语句周围尝试括号。
像这样:
SELECT news.id, news.slug, news.title, news.created_on FROM (news)
WHERE `published` = '1'
AND (
news.title LIKE '%running%'
OR news.body LIKE '%running%'
OR news.intro LIKE '%running%'
)
ORDER BY created_on desc