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?
ILIKE doesn't exist in mysql.
Common Resource Grep (crgrep) searches for table/column name and data matches and supports MySQL. Also searches other hard to search resources like content buried in archives.
LIKE and ILIKE allow pattern matching within character-based column data. Their syntax is identical, but LIKE is case-sensitive, while ILIKE is case-insensitive.
Use the LIKE or NOT LIKE comparison operators instead. The other type of pattern matching provided by MySQL uses extended regular expressions. When you test for a match for this type of pattern, use the REGEXP_LIKE() function (or the REGEXP or RLIKE operators, which are synonyms for REGEXP_LIKE() ).
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.
Perhaps the problem is the quotes, use " instead of ' to wrap the LIKE clause.
SELECT * FROM people
WHERE bio LIKE "%died%"
AND death_date IS NULL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With