lpa;10983914 wrote:Ashley Sheridan, probably we are talking about different things.
Not really, no.
Ashley Sheridan (et al.) have suggested that you eliminate the 'total_number' column altogether (and thus the UPDATE query becomes pointless) since you can instead perform a COUNT() at the time you retrieve the list of folder names to calculate the number of messages "on-the-fly" rather than using a stored value (which must be kept in sync with the actual count).
Why is it that you're ignoring that suggestion?
Multiple rows can only be updated if you are applying the same value to a particular column
This is entirely false, however it's also irrelevant.
lpa;10983914 wrote:So, I can't update multiple rows with just 1 query.
This is again false, however using COUNT() when retrieving the folders would negate the need to even address this at all.
lpa;10983914 wrote:Is it OK or it can be done better?
IMHO, it's not OK and it could be done much, much better.
For one, there's the obvious suggestion that's been beaten to death already - using COUNT() on the fly.
For another, if you wanted to keep the stored value for whatever reason (e.g. you're using InnoDB tables and/or COUNT() isn't performing as well as you'd like), I would recommend using triggers to automatically update this value whenever a message is created or deleted.
In a nutshell, you'd most likely have two triggers - one for 'ON INSERT' and one for 'ON DELETE.' Their respective functions should be obvious; the former increments the message count while the latter decrements the count.