多表关联的update语句

来源:互联网 发布:编程开发软件 编辑:程序博客网 时间:2024/05/23 00:06
MSSql的多表关联的update语句
例如A表 存在一下字段:
AID A1 A2 A3 A4

B表中存在字段:
BID B1 B2 B3 B4

如果实现用B表的所有字段更新A表中相应的字段,在MS SQL Server里面可以写成:
update A
set A1=B.B1,A2=B.B2,A3=B.B3,A4=B.B4
from A,B
where A.AID=B.BID

ORACLE UPDATE 多表关联的update语句

  -- update 超过2个值
   update customers a   -- 使用别名
   set    (city_name,customer_type)=(select b.city_name,b.customer_type 
                                     from   tmp_cust_city b 
                                     where  b.customer_id=a.customer_id)
   where  exists (select 1 
                  from   tmp_cust_city b
                  where  b.customer_id=a.customer_id
                 )

原创粉丝点击