Nested SQL / Incrementing Counter
I stumbled upon some SQL work I’ve done in the past that will increment a counter in a MySQL table. The table has (for instance) a primary key “ID” and a counter “count”. The SQL statement to increment count, given an ID is as follows:
UPDATE table SET count= ( SELECT count )+1 WHERE ID = 4 LIMIT 1
I’ve looked for this in the past and have been unable to find it, so hopefully it helps some others.
It works great on MySQL 4.*
If you don’t have this, you have to do two queries, one to pull the value, one to update with the incremented value. Since that is a hassle and ugly as can be, this is much more preferable.

Raybdbomb Said,
August 3, 2006 @ 5:00 pm
Just used this, saved me some time