Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql update math

Tags:

mysql

say p.products_price equals 1

why does:

UPDATE products p
SET p.products_price = (1 + p.products_price)
WHERE p.products_id = 8

make p.products_price equals 3?

It is adding 1 to the price and then doing it all over again? I am trying to do something a little more complicated but when it didn't work I broke it down to the simplest thing ever. Can I make some kind of temporary value here and calculate the new price and then set it to that?

Please help I am raging, Thanks.

MySQL client version: 4.1.22

edit: the column is decimal type, i tried the same update on an int column with the same result.

edit: this is not running in code so there is no chance of the code calling the same update twice

like image 690
Matthew Rapati Avatar asked Dec 05 '08 20:12

Matthew Rapati


1 Answers

UPDATE products    
SET products_price = (1 + products_price)    
WHERE products_id = 8

works like it should (removed table alias 'p')

like image 53
Matthew Rapati Avatar answered Nov 11 '22 14:11

Matthew Rapati