#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    97
    Rep Power
    18

    Add value to existing field with one query


    I want to add a value to a value that is already in the DB.

    For example sake this is what I would like to do:

    $ValueToAddToDB = 4

    UPDATE mytable SET field=add($ValueToAddToDB) WHERE id=555

    So in the above example, if "field was already 100, it would now be 104 after the update ran.

    Is there a mySQL function like add or sum?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    97
    Rep Power
    18
    field=field+$valueImAdding
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by gbrent
    field=field+$valueImAdding
    Thanks for posting the answer, I am assuming it works when subtracting or otherwise changing a value, because putting the field name into the right side of the definition makes it like a variable in an equation.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,927
    Rep Power
    378
    Yep

IMN logo majestic logo threadwatch logo seochat tools logo