updateleftjoin在MySQL和SqlServer中的⽤法
例如有两个表:user(id, uname, score), student(id, surname, personal_name, score)。现在需要将student表中的学⽣surname和personal_name拼接后与user的uname匹配,然后修改user表中对应⼈员的分数情况。实际使⽤中是设计到了⼦查询,本例可能并不太适合
(1)在MySQL中,可以直接使⽤:
update user a left join student b
on  a.uname = CONCAT(b.surname,b.personal_name)
set a.score = b.score
where a.score is null;
sql中update什么意思运⾏后user表数据如下:
(2)在sql server中,上述语句并不能正常运⾏,进⾏了如下修改:
update user  set score = b.score from user A
left join student B
on A.uname =  CONCAT(b.surname,b.personal_name)
where a.score is null;