update test.n s1
LEFT JOIN test.n s2
on s1.id=s2.id
set s1.`name`=s2.t,s1.t=s2.`name`
where s2.t is not null
更简单的方法是用中间列暂存:
update temp.s
set tem=a,a=b,b=tem
关联更新与此类似:
update test.n s1
LEFT JOIN test.m s2
on s1.`name`=s2.gender
set s1.t=s2.count
where s1.t is null
核心都是在update中使用关联。