开发者

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';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜