I have a table, 3 columns,
ID (prmiary, auto-inc),counter (UNSIGNED INT), text (VARCHAR)
There are 1 million rows.
I would like to go through the table and minus 1 from the counter value for each row (开发者_高级运维also, what happens if it is 0 and -1 happens [i set it as unsigned when I made the table? can a query handle this?).
What is the best mysql_query to do this using php?
UPDATE table SET counter = counter - 1
WHERE counter > 0
It should just not update when counter - 1 < 0, iirc.
I would use UPDATE LOW_PRIORITY table SET counter = counter - 1 WHERE counter > 0;
精彩评论