Today, in SQL database operation, you need to update the data in one table to another table, but I don't know how to succeed in the way I used to. The code is as follows:
Update table1 a set a.col1=b.col2 from table2 b where a.c= B.C
The above notation appears to be achievable in the context of Oracle, which is not validated in SQL Server anyway. The internet looked for a bit and finally found a solution, as follows:
Syntax supported by both ORALCE and DB2:
UPDATE A SET (A1, A2, A3) = (SELECT B1, B2, B3 from B WHERE a.id = b.id)
MS SQL Server does not support such a syntax, the corresponding wording is:
UPDATE A SET A1 = B1, A2 = B2, A3 = B3 from A left JOIN B on a.id = b.ID
Personal feeling MS SQL Server's update syntax is more powerful. MS SQL Server notation:
UPDATE A SET A1 = B1, A2 = B2, A3 = B3 from A, B WHERE a.id = b.id
The syntax for Oracle and DB2 is more cumbersome, as follows:
UPDATE A SET (A1, A2, A3) = (select B1, B2, B3 from b where a.id = b.id) where ID in (select b.ID from B where a.id = b.id)
About the UPDATE statement in SQL