7

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?

Aldwoni
  • 1,168
  • 10
  • 24
kirkaracha
  • 742
  • 2
  • 14
  • 23
  • 2
    Are you sure that it returns people who don't have 'died' in their bio? Remember it will also include words containing died such as studied, and imbodied. – Kibbee Nov 19 '10 at 16:56
  • share sample data which is behaving like this. – Channa Apr 21 '19 at 09:54

3 Answers3

5

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
Ben
  • 60,438
  • 111
  • 314
  • 488
5

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.

Yasen Zhelev
  • 4,045
  • 3
  • 31
  • 56
0

i would suggest you make bio upper case and have like "%DIED%" also make sure that death_date is really null, see if you get an answer from both where cases independently. What response are you getting?

Mauro Morales
  • 1,517
  • 2
  • 11
  • 12