MySql How to set a local variable in an update statement (Syntax?)

后端 未结 5 1586
[愿得一人]
[愿得一人] 2020-12-24 13:29

How can I set a variable while doing an Update statement? I can\'t seem to figure out the syntax.

So I want something like this below but it\'s saying the syntax is

5条回答
  •  隐瞒了意图╮
    2020-12-24 14:05

    I tested a similar query using a select and it worked for me, so I would rewrite your query as follows

    SET @tempVariable := 0;
    UPDATE myTable SET col1 = 5, col2 = (SELECT @tempVariable + 100);
    

    Hope that helps.

提交回复
热议问题