SQLite Forum

What is the recommended way to update multiple columns from a single select?
Login
You have two update options:

1. update

update MyTable
set val_a = src.val_a, val_b = src.val_b, val_c = src.val_c
from (select * from MyTable where snapshot_id = 1) as src
where MyTable.object_id = src.object_id
  and MyTable.snapshot_id = 2 


2. update

update MyTable set 
val_a = (select x.val_a from MyTable x where x.snapshot_id = 1 and x.object_id = MyTable.object_id),
val_b = (select x.val_b from MyTable x where x.snapshot_id = 1 and x.object_id = MyTable.object_id),
val_c = (select x.val_c from MyTable x where x.snapshot_id = 1 and x.object_id = MyTable.object_id)
where snapshot_id = 2