Take the 2-minute tour ×

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

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted
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.

share|improve this answer
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 worked sqlite.org/lang_delete.html Thanks again for your help. –  Satish Aug 10 '10 at 6:49
add comment

The LIMIT and ORDER options for DELETE in sqlite are optional, and it appears they aren't enabled on Android. Borealid's SQL above will work fine even without the quotes.

share|improve this answer
add comment

Your Answer


