如图,t1,t2表,我想通过t2来更新t1的name,试着写了一个
update t1 a set a.name=(select b.name from t2 b where a.id=b.id)
但这样的话,在t2中不存在的id=3的name就会成空,该怎么写呢?
update t1 A a set name= ( select b.name from t2 B where ID = a.ID )
where exists(select t2 1 from B where ID = a.ID )
select b.name from t2 b where a.id=b.id and b.name is not null.
问题是。。你T2中 是存在ID =3,但是name为空的行。
还是t2中 根本就没有这一行?
merge into table_1 t1
using table_2 t2
on( t1.id=t2.id )
when matched then
update name=t2.name;