We can use with-clause
+ column-name-list
+ select-stmt
from https://www.sqlite.org/lang_update.html to do something like this:
CREATE TABLE aa ( _id INTEGER PRIMARY KEY, a1 INTEGER, a2 INTEGER); INSERT INTO aa VALUES (1,10,20); INSERT INTO aa VALUES (2,-10,-20); --a bit unpleasant because we have to select manually each column and it just a lot to write WITH bb (_id,b1, b2) AS (SELECT _id,a1+2, a2+1 FROM aa) UPDATE aa SET a1=(SELECT b1 FROM bb WHERE bb._id=aa._id),a2=(SELECT b2 FROM bb WHERE bb._id=aa._id) WHERE a1<=1000 OR a2<=2000; --totally useless where clause but just so you don't update every row in aa by putting this where clause in the bb --soo now it should be (1,10,20)->(1,12,21) and (2,-10,-20)->(2,-8,-19), and it is SELECT * FROM aa; --even better with one select for each row! WITH bb (_id,b1, b2) AS (SELECT _id,a1+2, a2+1 from aa) UPDATE aa SET (_id,a1,a2)=(SELECT bb._id,b1,b2 FROM bb WHERE bb._id=aa._id) WHERE a1<=1000 OR a2<=2000; --totally useless where clause but just so you don't update every row in aa by putting this where clause in the bb --soo now it should be (1,12,21)->(1,14,22) and (2,-8,-19)->(2,-6,-18), and it is SELECT * FROM aa; --you can skip the with altogether UPDATE aa SET (_id,a1,a2)=(SELECT bb._id,bb.a1+2, bb.a2+1 FROM aa AS bb WHERE aa._id=bb._id) WHERE a1<=1000 OR a2<=2000; --totally useless where clause but just so you don't update every row in aa by putting this where clause in the bb --soo now it should be (1,14,22)->(1,16,23) and (2,-4,-17)->(2,-6,-18), and it is SELECT * FROM aa;
I hope sqlite is smart enough not to perform step-by-step queries, but according to the documentation it is.