Search code examples
androidsqlitecursorsql-like

How to put concise multiple like query


I have a code where I want to search the database with matches on the user's input using multiple like query.

code:-

String querysearch= "SELECT * FROM Data WHERE Value LIKE ? AND ObjectID LIKE ?"
cursor = sqldb.rawQuery(querysearch, new String[]{"%"+query + "%", " %"+query+"%"});

Based on what I've recently searched, I came up with that but unfortunately, it did not return any matches eventhough it has. Any help? Thanks!


Solution

  • Solved it. The problem is with me using the AND operator. If you want to strictly match your results, with the two conditions, use AND. But if you want whichever of your conditions to provide the match on your desired result, use OR.