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:
CREATETABLE Points(Id INTEGERPRIMARY KEY, valueINTEGER, player INTEGER, matchINTEGER);
Then you can use a subquery to find the one row you want to delete:
DELETEFROM Points WHERE Id =(SELECTMIN(Id) FROM Points WHEREvalue=1AND player=2andmatch=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"