Search code examples
sqlstringsqlitewhere-clausesql-like

Query to check if we have any row which start with input String


lets say have column with values

"Html", "Java", "JQuery", "Sqlite"

and if user enters

"Java is my favorite programming language"

then result should be

1 row selected with value "Java"

because entered sentence starts with "Java"

but if user enters

"My application database is in Sqlite"

then query should return empty.

0 row selected

because entered sentence does not start with "Sqlite".

I am trying following query:

SELECT * FROM demo where 'Java' like demo.name; // work

but if enter long text then it fails

SELECT * FROM demo where 'Java is my favorite programming language' like demo.name; // Fails

Solution

  • I think you want something like this :

    SELECT * FROM demo WHERE yourText LIKE demo.name || '%' ;