tags:

views:

74

answers:

1

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

+1  A: 
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.

Borealid
Thank you. That exact SQL worked. I am not really sure why the original SQL didn't work though. According to this documentation (for use of LIMIT in DELETE) it should've workedhttp://www.sqlite.org/lang_delete.htmlThanks again for your help.
Satish