incrementing a table column's data by one || mySql
iam having a table with columns like
id || counter
if i do something (some event) i want the coun开发者_开发技巧ter's value(at a particular id) to increase by one , currently iam doing this :
//get current value
current_value = select counter from myTable where id='someValue'
// increase value
current_value++
//update table with current value
update myTable set counter=current_value where id='someValue';
currently iam running 2 queries for this, please suggest me some way do it in one step.
Just run the math in the database:
update myTable set counter = counter + 1 where id = 'someValue';
精彩评论