Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (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 OR?

like image 526
LopezAgrela Avatar asked Sep 06 '25 13:09

LopezAgrela


1 Answers

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));
like image 110
waqaslam Avatar answered Sep 09 '25 03:09

waqaslam