开发者

Android Database usage

This may be a simple question as I have not done any database work for a while!

I have two tables with data like the below

Table 1 Rows with Primary Keys 1,2

Table 2 Rows with Foreign keys 1,2,3,4

I was to be able to perform a DELETE statement which will remove all rows from Table 2 that do not have a corresponding primary key 开发者_运维知识库in table 1, which in this case would result in only rows with foreign keys 1 & 2 being left in the table.

I should mention that this is on Android so I am using SQLite and also I am interested in the ease of doing this via a content provider.

Thanks for any help


Try this:

String SQL="DELETE FROM Table2
WHERE (Table2.FQ1,Table2.FQ2) NOT IN (SELECT PK1,PK2 FROM Table1)";
db.SQL(SQL);

But i'm not sure that the (Table2.FQ1,Table2.FQ2) sentence will run into the NOT IN

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜