我尝试将parts_keywords中的所有行都包含在parts_questions中。不幸的是,我得到了两个表的所有行。
SELECT *FROM parts_keywords
LEFT OUTER JOIN parts_questions ON parts_keywords.ID = parts_questions.question_id
WHERE parts_questions.question_id IS NULL
AND parts_keywords.term LIKE '%where%' || parts_keywords.term LIKE '%how%' || parts_keywords.term LIKE '%who%' || parts_keywords.term LIKE '%what%'
ORDER BY parts_keywords.ID DESC lIMIT 15
我尝试使用OR而不是||。我也尝试使用MATCH而不是LIKE无济于事。
当我只使用一个LIKE元素时,例如'who'我得到了正确的结果。但是,对我来说,将所有LIKE元素的结果放在一起非常重要。
请帮忙
答案 0 :(得分:0)
你的OR条款
附近缺少()SELECT *
FROM parts_keywords
LEFT OUTER JOIN parts_questions ON parts_keywords.ID = parts_questions.question_id
WHERE parts_questions.question_id IS NULL
AND (parts_keywords.term LIKE '%where%'
OR parts_keywords.term LIKE '%how%'
OR parts_keywords.term LIKE '%who%'
OR parts_keywords.term LIKE '%what%')
ORDER BY parts_keywords.ID DESC lIMIT 15
答案 1 :(得分:0)
尝试使用括号
SELECT * FROM parts_keywords pk
LEFT OUTER JOIN parts_questions pq ON pk.ID = pq.question_id
WHERE pq.question_id IS NULL
AND ( pk.term LIKE '%where%' OR pk.term LIKE '%how%' OR pk.term LIKE '%who%' OR pk.term LIKE '%what%' )
ORDER BY parts_keywords.ID DESC lIMIT 15