目的:两个表t1,t2,t1里面的字段,id,name,t2也是,将t2表和t1表里面相等的id的记录的name字段更新到t1表里面
1、
update t1 set (name) = (select t2.name from t2 where t2.id = t1.id)
where exits (select 1 from t2 where t1.id = t2)
对于第二行,可能有的人可能不用,但是这会让t1的所有记录都会更新,在t2里面有对应数据的时候正确更新,没有对应数据的时候就是null
2、
update (select t1.id, t1.name tn1, t2.id, t2.name tn2 from t1, t2 where t1.id = t2.id)
set tn1 = tn2
前提条件是t2的id是主键
今天先写到这里