I am try to get all the rows in parts_keywords not included in parts_questions. Unfortunately, I am getting all the rows of both tables.
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
I have tried using the OR instead of ||. I have also tried using MATCH instead of LIKE to no avail.
When i use only one LIKE element, such as 'who' i get the correct results. However, it is important for me to get result for all LIKE elements together.
Please help
Try using paranthesis
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