Android的删除查询 [英] Android Delete Query

查看:121
本文介绍了Android的删除查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除一个表中没有在另一个表中的相应的ID的所有行。因为显然SQLite不支持加盟删除我试图做沿着这些路线的东西:

I'm attempting to delete all rows in one table that do not have a corresponding ID in another table. Since apparently SQLite does not support joins in deletes I am trying to do something along these lines:

    DELETE FROM my_table WHERE my_id NOT IN (SELECT _id FROM my_table2);

不过,我显然不能用rawQuery,因为它返回一个指针,所以我必须使用删除功能。我有一些麻烦这个工作。这是我想要的查询:

However, I apparently can not use rawQuery since it returns a cursor so I have to use the delete function. I'm having some trouble getting this working. Here is the query I'm trying:

    mDb.delete("my_table", "my_id NOT IN ?", new String[]{"(SELECT _id FROM my_table2)"});

感谢。

推荐答案

您不应使用.rawQuery,如你所说,但您可以使用.execSQL()来完成它。我经常用它来删除自己。

You shouldn't use a .rawQuery, as you stated, but you can use .execSQL() to accomplish it. I regularly use it for deletions myself.

这篇关于Android的删除查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆