SQLite Delete One Single Row
I have a SQLite table defined this way: CREATE TABLE Points(value INTEGER, player INTEGER, match INTEGER) In the execution, I may have several identical columns, and I want a call
Solution 1:
The delete statement you wrote will indeed delete all matching rows. Try to use the built-in column ROWID, read the first line, save the rowid, and then delete where ROWID= the value you selected.
Solution 2:
Try this
String _val=""+1;
String _player=""+3;
String _match=""+3;
db.delete(TABLE_NAME,"value=? AND player=? AND match=?",new String[] {_val,_player,_match});
Solution 3:
The usual way to do this is to assign every table a unique identifier for each row. Like this:
CREATE TABLE Points(Id INTEGER PRIMARY KEY, value INTEGER, player INTEGER, match INTEGER);
Then you can use a subquery to find the one row you want to delete:
DELETE FROM Points WHERE Id =(SELECT MIN(Id) FROM Points WHERE value=1 AND player=2 and match=3);
This example deletes the oldest record entered first (the oldest has the lowest unique key Id)
Post a Comment for "SQLite Delete One Single Row"