Search code examples
mysqlselectnullwhere-clausesql-like

MySQL Select with LIKE and WHERE


I have a table of biographical data, and I need to do a query that selects people who have the word "died" in their bio and whose death date is NULL. This doesn't work:

SELECT * FROM people
WHERE bio LIKE '%died%'
AND death_date IS NULL

That selects everyone whose death_date is null, but also selects people who don't have the word "died" in their bio. Can I do this in one query?


Solution

  • It could be a word like 'completelydied' and they are still going to be selected. Check carefully if 'died' phrase does not exists as part of some word in the records that you got selected.