Page 1 of 1

assinment operators in mysql

Posted: Tue Jun 29, 2004 1:00 pm
by snpo123
Is there any way to use basic mathamatics in your mysql queries? The following doesnt work for me, but is basicly what I am trying to acomplish:

Code: Select all

update users set whatever +=12 where user_id=1
I'm probably doing it wrong. If mysql doesnt have anything like this, then I will just have to do it from php :cry: . Not the worst news ever, but still...

if anybody knows thhe answer to this then please tell me.

Thanks.

Posted: Tue Jun 29, 2004 1:02 pm
by markl999
update users set whatever = whatever+12 where user_id=1

Posted: Tue Jun 29, 2004 1:09 pm
by snpo123
So lets say that on a certian row where a userid=12, there is a coloum with a value of 5. If I wanted to add 12 to it I would use this syntax? Update users set coloum = coloum+12?

Posted: Tue Jun 29, 2004 1:18 pm
by markl999

Posted: Tue Jun 29, 2004 3:25 pm
by phice
I would personally add paranthesis around the "column + 12", so you get: UPDATE users SET column = (column + 12)