I have a query to substract a value stored on the DB.
UPDATE tablename SET
available = IF( available > 0, available - " . $var . ", 0 ) ,
purchases = purchases + 1
WHERE condition
Is posible to get the new value of field available without make a new SELECT and then penalize the performance?
I haven’t tested this code, but I’m
87,587%sure it works.An update statement does not return a resultset, however you can set a @var variable and select from that.
This will break if you update more than 1 row however: when updating more than 1 row, @fastpeek will only show the last update. Hence the limit 1.
You still need an extra select, but it will not need to query the database, it will just retrieve the @var from memory.