(select colA,colB,doc from tableA;) --把他当作 tableA 表update tableB a set (a.colA,a.colB)=(select colA,colB,doc from tableA ..........)
接下来怎么写?
我 就想更新 tableB 的 colA 和 colB 字段,他们的值是上面的第一条sql 查出来的,
两个关联条件  就是  tableA 的 doc 字段= tableB的 doc 字段,,,
sql 该怎么写?
我 记得 上面的 update  sql 好像 还有 什么  where  exists  什么的 ?
怎么写?

解决方案 »

  1.   

    update tableB a set (a.colA,a.colB)=(select colA,colB from tableA where doc = a.doc and rownum=1) where exists(select 1 from tableA where doc = a.doc )
      

  2.   

    oracle 9i以后的版本有这个函数,不知道你是不是用oracle
    merge into tableA a 
    using tableB b
    on a.doc = b.doc
    when matched then 
    update set a.colA = b.colB
    你可以看下API,这个函数执行时效率,对两张表只需要检索一次