有兩個表
table1(id,pcode,pname,type) 初始數據只有id、pcode,pname、type為空table2(id,pcode,pname,type)
根據table1和table的相同字段pcode,用table2的數據更新table1的pname和type字段。
例如:table1 和 table2 的id相同,需要把table2中的字段更新到table1里面
update table1
set pname=table2.pname,
type=table2.type
from table2
where table1.pcode=table2.pcode
也可以加where條件,使用適當的篩選條件來限制更新的范圍。
UPDATE b
SET column1 = a.column1,column2 = a.column2,column3 = a.column3
FROM a
WHERE a.id = b.id
AND b.id = 1