我建立一个Android应用程序,其中我公司采用的数据辅助类来存储数据。
现在我面临的问题是如何从表中删除前老10的数据。
我使用下面的查询,但我的应用程序崩溃。
公共无效deleteRec(){
字符串ALTER_TBL =从删除+ TBL_NAME +
为了通过_id LIMIT 3);;
db.execSQL(ALTER_TBL);
}
和呼吁使用 -
新DatabaseHelper(getApplicationContext())deleteRec()。
解决方案
在尝试如下:
字符串ALTER_TBL = + TBL_NAME +从删除哪里的rowid IN(选择ROWID+ TBL_NAME +极限10);
希望这将帮助你。
I am building an android application where I am using data helper class to store the data.
Now the problem I am facing is How can I delete top old 10 data from table.
I am using below query but my application crashed.
public void deleteRec() {
String ALTER_TBL ="delete from " + TBL_NAME +
" order by _id LIMIT 3);";
db.execSQL(ALTER_TBL);
}
And calling using -
new DatabaseHelper(getApplicationContext()).deleteRec();
解决方案
Once try as follows
String ALTER_TBL ="delete from " + TBL_NAME + " where rowid IN (Select rowid from " + TBL_NAME + " limit 10)";
Hope this will helps you.