tags:

views:

36

answers:

1

iam having a table with columns like

id || counter

if i do something (some event) i want the counter'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.

+8  A: 

Just run the math in the database:

update myTable set counter = counter + 1 where id = 'someValue';
Joseph Mastey