Daniel Nysveen
Daniel Nysveen

Reputation: 161

Android Sqlite Delete with Limit

I have a database where it is possible for several rows to be identical. I want to have the ability to only delete the first of the identical rows. I tried using the LIMIT statement but I get an SQLiteException error when I try to use LIMIT. I've tried doing several google searches and I've come up with nothing. Can you not use LIMIT and delete on android? Below is my exact code. Thanks

db.execSQL("DELETE FROM "+table+" WHERE " + someColumn+"='"+somevalue+"' LIMIT 1")

Upvotes: 2

Views: 1900

Answers (1)

Terence Lui
Terence Lui

Reputation: 2808

It may not enable for Android SQLite, since it's optional:http://www.sqlite.org/lang_delete.html

What you have to do is to SELECT all you want (assume you dont have ORDER BY). get the id of the first one, DELETE FROM table WHERE id="123456".

Hope its help.

Upvotes: 5

Related Questions