-1

I want to search for the occurrence of words in a database row. I use SQLite as a database. The search needs to be case-insensitive.

Let's say row x is Hello. Today is Monday and I want to search for Hello Monday Bye and still return the row x because the Hello and Monday exist in the row.

I used Like operator %Hello%Tuesday%Bye% but this defiantly doesn't work and I can't use Glob because it's not case-insensitive. Any suggestion, how can I do the search?

Also, the order shouldn't matter and Monday Hello should return a row as well

taraf
  • 777
  • 2
  • 10
  • 28

2 Answers2

1

You can extend SQLite with regular expressions and then use:

where col regexp replace($searchfor, ' ', '|')

This will return any time there is a match with any of the values.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

First create a recursive CTE to split the string 'Hello Monday Bye' which contains the words you search for.
Then join it to the table:

with cte as (
    select null word, 'Hello Monday Bye' || ' ' rest
    union all
    select substr(rest, 1, instr(rest, ' ') - 1),
           substr(rest, instr(rest, ' ') + 1)
    from cte
    where length(rest) > 0
  )
select distinct t.* 
from tablename t inner join cte c
on t.col like '%' || c.word || '%'

See the demo.

forpas
  • 160,666
  • 10
  • 38
  • 76