goohugo / myblog

该仓库为个人博客,请不要提 issue ,该仓库后端参考了 @yihong0618 的 gitblog 项目,前端参考了@LoeiFy 的 Mirror 项目,感谢!
MIT License
2 stars 1 forks source link

数据库更新表数据,从另一个表中取值 #29

Open goohugo opened 11 months ago

goohugo commented 11 months ago

SQL SERVER

UPDATE  A set A.C=B.C 
from  tableA  as A(别名),tableB as  B (别名)
where A.列= B.列

MySQL

UPDATE tableA  as A
inner join tableB as  B  
on  A.列= B.列
set  A.C=B.C 

当A表与B表某个字段值相等时,更新A表某列值等于B表某列值

DB2

UPDATE A_TEST as atest
set atest.ORG_CODE=(select ctest.code from C_TEST ctest where atest.id = ctest.id)
where atest.id in  (select ctest.id FROM TEST ctest);