Reputation:
i have this code in sqlite
self.cursor.execute('update inventory set cost=cost+? where account=?',(value,account))
i just want to sum the value
to the cost
just in one row what ever if that was the first row or last, but the problem is when i execute
, it sum the value to all rows that have the account
name
just to know it don't have any error it just issue in the code
Upvotes: 1
Views: 62
Reputation: 164069
Use a subquery in the WHERE
clause to get the max rowid
of the account
that you want and update only that:
UPDATE inventory
SET cost = cost + ?
WHERE rowid = (SELECT MAX(rowid) FROM inventory WHERE account = ?);
Upvotes: 1