assinment operators in mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
snpo123
Forum Commoner
Posts: 77
Joined: Sat Apr 17, 2004 6:31 pm

assinment operators in mysql

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

update users set whatever = whatever+12 where user_id=1
User avatar
snpo123
Forum Commoner
Posts: 77
Joined: Sat Apr 17, 2004 6:31 pm

Post 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?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

I would personally add paranthesis around the "column + 12", so you get: UPDATE users SET column = (column + 12)
Image Image
Post Reply