Reputation: 7574
I have the following query that returns a Cursor based on how many records have an awayreasontypeid of '2'. It works fine.
How can i run the same query but return a Cursor of all the records that have an awayreasontypeid of either '2' or '0'?
// table AwayReason column names
public static final String C_AWAYREASON_ID_INDEX = BaseColumns._ID;
public static final String C_AWAYREASON_ID = "awayreasonid";
public static final String C_AWAYREASON_NAME = "awayreasonname";
public static final String C_AWAYREASON_TYPE_ID = "awayreasontypeid";
public Cursor queryCarerAwayReasons(){
SQLiteDatabase db = dbhelper.getReadableDatabase();
String[] carer = { "2" };
Cursor c = db.rawQuery("SELECT * FROM " + DBHelper.TABLEAWAYREASON + " WHERE awayreasontypeid = ?", carer);
return c;
}
Thanks in advance
Matt
Upvotes: 0
Views: 52
Reputation: 152817
You can use IN
:
String[] carer = { "2", "0" };
Cursor c = db.rawQuery("SELECT * FROM " + DBHelper.TABLEAWAYREASON + " WHERE awayreasontypeid IN (?,?)", carer);
Upvotes: 1