... Or least I suppose it's not
I currently have the following update with an if statement:
And it works fine (I realize that with FLOOR() is stupid to check if @gain >= 1, explaination follows). But I want to update column2 too, but only if column1 is updated, and I like to do it all in one statement without locking the table. I want to do something like this:Code:UPDATE table SET column1 = column1 + IF((@gain := FLOOR((value1 - column2) * value2)) AND @gain >= 1, IF(@gain + column1 > value3, value3, @gain + column1), 0) WHERE id = 1
In the last query column2 is updated correctly, but column1 is always only increased by 1, which isn't so strange since the AND operator would do that with two statements that assert true. But how should I do to achieve wanted result?Code:UPDATE table SET column1 = column1 + IF((@gain := FLOOR((value1 - column2) * value2)) AND @gain >= 1, (@var := value1) AND IF(@gain + column1 > value3, value3, @gain + column1), (@var := column2) AND 0), column2 = @var WHERE id = 1




Bookmarks