0

I am new in java but I am trying to code:

      SQLiteDatabase db = this.getWritableDatabase();
        //db.execSQL("delete from " + TABLE_BOOKMARKS + " where " + KEY_ID + "  not in (select " + KEY_ID + " from " + TABLE_BOOKMARKS + " order by " + KEY_ID + " limit 10)" );
        //db.execSQL("DELETE FROM " + TABLE_BOOKMARKS + " WHERE " + KEY_ID + " NOT IN (SELECT TOP 10 " + KEY_ID + " FROM " + TABLE_BOOKMARKS + ")" );

        db.execSQL("Delete From "+TABLE_BOOKMARKS+"  where "+ KEY_ID  + " not in (Select Top 10 "+ KEY_ID +" from "+ TABLE_BOOKMARKS + " order by " + KEY_ID +")");
        db.close(); // Closing database connection

you can see in the code, I have tried in 3 different ways but when I run it my application returns error and stops!

I got this error:

android.database.sqlite.SQLiteException: near "10": syntax error: , while compiling: Delete From bookmarks where id not in (Select Top 10 id from bookmarks order by id)

1

1 Answer 1

1

You can try

db.execSQL("Delete From "+TABLE_BOOKMARKS+"  where "+ KEY_ID  + " not in (Select "+ KEY_ID +" from "+ TABLE_BOOKMARKS + " order by " + KEY_ID +" limit 10)");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.