aneela
aneela

Reputation: 1619

How to find substring in Where clause in Sqlite query Android

I here want to know the how should I write the where clause in sqlite query in android as most of the examples I have seen say address = ? but I want to check substring. Is there a way to check substring of the string present in the database columns.Maybe this is very simple but I didnot find any example of doing this yet.

Upvotes: 1

Views: 4309

Answers (2)

Yugandhar Babu
Yugandhar Babu

Reputation: 10349

Use a string like below in place of WHERE clause

-> If the sub string is at begining of column value

columnName+" LIKE '"+subString+"%'"

-> If the sub string is at end of column value

columnName+" LIKE '%"+subString+"'"

-> If the sub string is at middle of column value

columnName+" LIKE '%"+subString+"%'"

Upvotes: 5

jeet
jeet

Reputation: 29199

Yes use LIKE operator to check substring in where clause.

Learn SQL LIKE

Upvotes: 7

Related Questions