I used a code similar to the following code to search the database person name :
cursor.query(select column from Table where column_person_Name="John");
But now I want to search the names of a few people together,How to do it?
I used a code similar to the following code to search the database person name :
cursor.query(select column from Table where column_person_Name="John");
But now I want to search the names of a few people together,How to do it?
The way to do that using SQlite would be using IN:
SELECT * FROM persons WHERE name IN ("John", "Doe");
In Java, having an array of Strings, you could do it like that:
final String[] namesArray = {"John", "Doe"};
// Pad the Strings with quotes: John -> 'John'
for (int i = 0; i < namesArray.length; i++) {
namesArray[i] = "'" + namesArray[i] + "'";
}
// Join the Strings: 'John', 'Doe'
final String names = TextUtils.join(",", namesArray);
final String query = "SELECT * FROM persons WHERE name IN ("+names+")";
This results in:
SELECT * FROM persons WHERE name IN ('John','Doe')
Room supports Collections as a query argument.
Query in Room is like:
@Query("SELECT first_name, last_name FROM user WHERE region IN (:regions)")
public List<NameTuple> loadUsersFromRegions(List<String> regions);
Check official guides.