alberking alberking - 4 months ago 18x
Android Question

How to delete rows in SQLite with multiple where args?

I want to delete rows which satisfy any of multiple conditions.

For example, I pass a list of IDs, and I want to delete all rows with these

(IDs are unique).

This would be:

String[] ids = {"0", "1", "2", "3",...};
database.delete("rows" , "id=? OR id=? OR id=? OR id=? OR ..." , ids );

Is there any way to do it compact without multiple


You may get it done through db.execSQL method and SQL's IN keyword. For example:

String args = TextUtils.join(", ", ids);

db.execSQL(String.format("DELETE FROM rows WHERE ids IN (%s);", args));