-1

Suppose I have a database with:

John Smith - 103

Jane Doe - 287

Mike Smith - 371

And I have a string like:

"Let's see the value of John Smith in the database"

I need a way to check if this string has any of the names in it and get the value associated with the name.

How can I do this in sqlite?

This is not the same as the question linked, it's the inverse. I have the string and I am looking for a pattern that matches it.

If I did:

SELECT *
FROM TABLE
WHERE column LIKE '%string%'

I would get nothing.

It would be:

SELECT *
FROM TABLE
WHERE string LIKE '%column%'

But I don't think this can be done like this.

forpas
  • 160,666
  • 10
  • 38
  • 76

1 Answers1

0

You can use sqlite instr:

instr(X,Y)

The instr(X,Y) function finds the first occurrence of string Y within string X and returns the number of prior characters plus 1, or 0 if Y is nowhere found within X. Or, if X and Y are both BLOBs, then instr(X,Y) returns one more than the number bytes prior to the first occurrence of Y, or 0 if Y does not occur anywhere within X. If both arguments X and Y to instr(X,Y) are non-NULL and are not BLOBs then both are interpreted as strings. If either X or Y are NULL in instr(X,Y) then the result is NULL.

Something like:

SELECT * from table
WHERE instr("Let's see the value of John Smith in the database",name) <> 0

You might want to lower() or upper() all strings to handle case.

DinoCoderSaurus
  • 6,110
  • 2
  • 10
  • 15