Carnal
Carnal

Reputation: 22064

Android SQLite delete multiple rows

I want to delete all rows in a table with a specific ID (not primary key). I have tested two different methods, but they only remove the first row it finds with the specific ID:

db.delete(CalendarTable.TABLE_NAME, "repeat_group="+repeatGroup, null);

and

db.delete(CalendarTable.TABLE_NAME, "repeat_group=?", new String[]{Integer.toString(repeatGroup)});

None of these methods works, how can I remove ALL rows in a table with this specific ID? Thanks in advance!

UPDATE: Lol, the method above did work! It was just me the stupid one that called the my own method delete() instead of deleteRepeatGroup(), guess I'm too tired! Anyways, thank you guys for taking your time.

Upvotes: 1

Views: 7234

Answers (2)

banzai86
banzai86

Reputation: 747

If everything else fails, you can try the following. Get all rows in the table with the ID you are trying to delete and save the rowID's in an array. Then iterate over the array and delete each row.

I hope this works as expected

Upvotes: 1

Hanry
Hanry

Reputation: 5531

you can use

String urQuery = "delete from tablename where Id in ("
    + Id + ")";

here Id may have all ids separated by comma ex. "id1,id2".

Upvotes: 1

Related Questions