公司做的业务有个需求是将A表中的某些字段数据,更新到B表中的相应含义的字段中。
假设A、B表的字段如下:

  • A表
userIdusernamephone
1皮皮156235xxxx
2李柯156235xxxx
3王杰156234xxxx
4柳梦156244xxxx
  • B表
userIdusernamescorecoursephone
180语文
185数学
352语文
267数学

现在B表中的username和phone字段是空的,需要从A表中,查找出相应的值插入B表中,SQL语句如下:

update B, A
set 
	B.username = A.username,
	B.phone = A.phone
where 
	B.userId = A.userId

update 
	B join A on B.userId=A.userId
set 
	B.username = A.username,
	B.phone = A.phone 
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐