Rani
Rani

Reputation: 47

filtering database results in android based on substring

I am working on an android app that has a database in which one of the columns is called "name". I receive from the user a string which is a search term, and I need to run a check for every row in the database checking if the "name" column contains that search term.

i.e. if i got one row with "skyrim" in the name column, and the search terms is "sky" I need that skyrim row to be returned in cursor resulting from the query (as well as any other rows containing the substring "sky" under their "name" column).

I tried fetching all rows and then looping over them with a java test to see if the name contains the substring using "contains" string method, but then realized I can't delete rows from cursor...

so I guess that leaves me only to do the test in the sql query method itself, any pointers on how to do it?

Upvotes: 1

Views: 302

Answers (1)

bsimic
bsimic

Reputation: 926

The simple solution would be to make your query something like:

SELECT * FROM table_name WHERE name LIKE '%sky%';

This in MySQL is case insensitive as well.

Upvotes: 2

Related Questions