MySQL Select with LIKE and WHERE

I have a biographical data table, and I need to make a request that selects people who have the word "died" in their biography and whose death date is NULL. This does not work:

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

This selects everyone whose death_date is NULL, but also selects people who do not have the word "died" in their biography. Can I do this in one request?

+6
null mysql select sql-like where
source share
3 answers

It may be a word like "fulldied" and they will still be selected. Check carefully if the phrase "died" does not exist as part of a word in the entries you have selected.

+5
source share

Perhaps the problem is with quotes, use "instead" to wrap the LIKE clause.

 SELECT * FROM people WHERE bio LIKE "%died%" AND death_date IS NULL 
+3
source share

I suggest you make bio-uppercase and have "% DIED%" also to make sure death_date is really invalid, see if you get an answer from both cases independently. What answer do you get?

0
source share

All Articles