I’m trying to UPDATE a column for a user, so that they can only ADD a value to the existing value. So for example, if the table looked like this:
UserID 3
Total 12
User adds 4, so it’s changed to:
UserID 3
Total 16
I could obviously do this by doing a query, getting the column value, adding it to the new value, and then updating that column… but I was wondering if there was a way to do it without using a SELECT statement first. Perhaps something using SUM()?
So the query might go:
UPDATE Users SET Total=SUM(Total + :total) WHERE UserID = :userID;
If so, what’s the correct syntax?
Thanks!
You don’t need the
SUM()since you are just adding the values,SUM()adds the values of a column together.