Quick newbie MySQL question. What would be the simplest way to ensure that the minimum value of a given field is 0?
Basically, we have a script that runs automatically and subtracts an integer value from the value of a field every 15 minutes--but we want any entry that gets to 0 to stay at 0 and not go negative.
This could be simply done with a loop in PHP but I'm trying to limit calls to the database...
Is there a simple way to either make the minimum value for a field 0 or make it so any negative value put in that field automatically becomes 0?
Thanks!
Have you tried a simple conditional "WHERE" or is the problem more complex than that?
UPDATE mytable SET mycolumn=mycolumn-1 WHERE mycolumn>0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With