Updating multiple records sql

In the case of Postgre SQL, it can be done using a FROM clause with UPDATE, like this: This does an INNER JOIN between the tables “staff” and “updates” where the column “name” matches.

updating multiple records sql-86updating multiple records sql-49updating multiple records sql-35updating multiple records sql-42

But we can group the updates according to the value being set, and then do one UPDATE statement per distinct value.If only one of these is the PK, then add the other field to the UPDATE list.If neither of them is a primary key (that seems unlikely) then this approach will always create new records - probably not what is wanted.New Value From [table] t1 join ( Select 'Foo' as New Value, 23 as My Id union all Select 'ASD' as New Value, 47 as My Id union all Select 'FGH' as New Value, 83 as My Id ) as derived1 on t1. Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Leave a Reply