dimanche 24 juillet 2016

MySql: any way to: UPDATE $tableName SET value=LEAST(value+$change, maxValue)

As the question-title says i am searching for a way to achieve this in only one sql-call:

UPDATE accountEnergy SET value=LEAST(value+$energyChange, maxValue)

My solution with two calls:

mysqli_query($db, "UPDATE accountEnergy SET value=value+$energyChange WHERE accountId=$accountId");
mysqli_query($db, "UPDATE accountEnergy SET value=maxValue WHERE accountId=$accountId AND value>maxValue");

Aucun commentaire:

Enregistrer un commentaire