删除的行指定数量的SQLite数据库 [英] Deleting specified number of rows from SQLite database

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

问题描述

我想用下面的语句从数据库中删除6行,但我得到所示的错误以下

。execSQL

getWritableDatabase()(DELETE FROM tblname ORDER BY _id ASC LIMIT 6;);

错误: 致:android.database.sqlite.SQLiteException:近序:语法错误:DELETE FROM tblname

我试图重新格式化SQL以不同的方式,但我不能让它的工作。我在想什么?非常感谢您的帮助

解决方案

  DELETE FROM tblname WHERE`_id` IN(SELECT`_id`从tblname ORDER BY`_id` ASC LIMIT 6)
 

我觉得你的问题可能已经被引用了 _id ,虽然。

I am trying to remove 6 rows from the database using the following statement but i get the error shown below

getWritableDatabase().execSQL("DELETE FROM tblname ORDER BY _id ASC LIMIT 6;");

Error: Caused by: android.database.sqlite.SQLiteException: near "ORDER": syntax error: DELETE FROM tblname

I tried reformatting the SQL in different ways but i couldn't get it to work. What am i missing? Thanks a lot for your help

解决方案

DELETE FROM tblname WHERE `_id` IN (SELECT `_id` FROM tblname ORDER BY `_id` ASC LIMIT 6)

I think your problem may have been quoting the _id, though.

这篇关于删除的行指定数量的SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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