数据库根据表的某一字段更新其他表内容

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/jiangwudidebaba/article/details/90635914

实际工作中常出现根据一个表的内容更新另一个表的内容,不同数据库直接的写法也有不同地方,总结一下 :

不同数据库的更新数据:

ORACLE:

update TBALE1 set COL = 
(select COL from TBALE2 where TBALE1.COL1 = TBALE2.COL1)
where exists (select 1 from TBALE2 where TBALE1.COL1 = TBALE2.COL1)

mysql:

UPDATE t1 set name = (select name from t2 where t1.id = t2.id)


update table_1 t1,table_2 t2 set t1.column = t2.column where t1.id = t2.pid;

猜你喜欢

转载自blog.csdn.net/jiangwudidebaba/article/details/90635914
今日推荐