Decrement value in mysql but not negative
问题 I want to decrement a value when user delete it in php and mysql. I want to check not to go below than 0. If value is 0 then do not decrement . mysql_query("UPDATE table SET field = field - 1 WHERE id = $number"); If field is 0 then do not do anything 回答1: Add another condition to update only if the field is greater 0 UPDATE table SET field = field - 1 WHERE id = $number and field > 0 回答2: You could prevent the new value to drop below zero by using GREATEST(). If the value drops below zero,