Reputation: 3669
Is it possible to get the current value of a field, use it as a variable in a calculation, then update the field based on the result?
For example the record with the ID "1" in table1 has a value of "2"
SELECT table1
WHERE ID = "1"
SET RESULT to CurrentID
RESULT = CurrentID + 1;
Upvotes: 22
Views: 29113
Reputation: 499072
This will set the result
column to the value of the CurrentID
column (plus 1) of the same row, for any row that has an ID
column that equals "1":
UPDATE table1
SET result = CurrentID + 1
WHERE ID = "1"
Upvotes: 24