I have read lots of post about how to update multiple columns but still can\'t find right answer.
I have one table and I would like update this table from another table.
TSQL does not support row-value constructor. Use this instead:
UPDATE table1
SET a = t2.a,
b = t2.b,
(...)
FROM
(
SELECT ..... with join ... WHERE ....
) t2
WHERE table1.id = table2.id
The above solution will work only for MSSQL. In case of MySql you just need to first declare the tables
UPDATE
table1 t1 ,table2 t2
set
t1.field=t2.field
where
t1.id=t2.id;
In my case this worked..!!
You don't need to use a sub-query you can also simply do the following....
Update t1
set t1.a = t2.a
,t1.b = t2.b
,t1.c = t2.c
,t1.d = t2.d
.......
from table1 t1
JOIN table2 t2 ON t1.id = t2.id
WHERE .......
The UPDATE SET commands implicitly apply on the table specified by , and it is not possible to specify the table on the SET operation.
Edit: Specify only the column name you want to update, do not mention the table.