场景:两张表有一个共有的字段关联,比如说A表,B表都有一个关联的id,现在想根据id,将A表的name字段更新到B表的name字段上
SQL:
update tab1
set val = (select val
from tab2
where tab1.id = tab2.id)
where exists(select 1 from tab2 where tab1.id = tab2.id);
参考:
场景:两张表有一个共有的字段关联,比如说A表,B表都有一个关联的id,现在想根据id,将A表的name字段更新到B表的name字段上
SQL:
update tab1
set val = (select val
from tab2
where tab1.id = tab2.id)
where exists(select 1 from tab2 where tab1.id = tab2.id);
参考: