ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Update 多个关联表SQL的写法

Update 多个关联表SQL的写法

原创 Linux操作系统 作者:oracle_ace 时间:2007-12-10 18:49:58 0 删除 编辑

更新一列:
update mytab a set name=(select b.name from goal b where b.id=a.id)
where exists (select 1 from goal b where b.id=a.id);

更新多列:
update mytab a 
   set  (name,address)=(select b.name,b.address 
                                     from   goal b
                                     where  b.id=a.id)
   where  exists (select 1
                  from goal b
                  where  b.id=a.id )

特别是要注意exists后面的语句:)这会让目标行不至于为NULL

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12361284/viewspace-349/,如需转载,请注明出处,否则将追究法律责任。

下一篇: Oracle in and exist
请登录后发表评论 登录
全部评论

注册时间:2007-12-10

  • 博文量
    284
  • 访问量
    843145