如何从android中的特定SQlite表中删除多条记录

时间:2012-02-13 13:05:08

标签: android sqlite

我创建了一个如下表格:

ID    Name    Phone   Address
-----------------------------
1     xyz       980      abc
2     sdf       382      sdff
3     hdj       322      abc
4     jks       346      abc
5     sdfd      344      abc

我想删除所有包含Address = "abc"Phone = {"980", "346", "322"}

的记录

如何在Android SQLite中完成上述查询?

2 个答案:

答案 0 :(得分:2)

它应该足够吗?

db.rawQuery("DELETE FROM my_table WHERE column_address='abc'
AND column_phone IN ('980', '346', '322')");

如果您想通过删除方法执行此操作,那么我假设您可以通过以下方式执行此操作:

    for(String phone : phoneNumbers){
        db.delete("my_table", "column_address = ? AND column_phone = ?",
        new String[]{"abc", phone});
    }

答案 1 :(得分:1)

这会对你有所帮助

delete from Table where Address = 'abc' and (Phone = '980' or Phone = '980' or Phone = '322')