I want to write query like this:
SET @id := 0;
UPDATE table1
SET
field1 = @id + 1,
@id := @id + 1
And get error message:
#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '@id := @id + 1' at line 3
How write this query correctly?
You can do it like this, with the assignment and increment combined:
EDIT: you can even use an
ORDER BYon such an UPDATE query to specify the order in which the numbers should be assigned.