表AA : code, desc, others
表BB : code, desc_cn, others现在希望把BB中的desc_cn列的值,插入到AA中desc列里,条件是AA.code = BB.code请问这样的SQL该如何写?多谢!!

解决方案 »

  1.   

    update aa a1
    set a1.desc=(select b1.desc_cn from bb b1 where b1.code=a1.code)
    where exists ( select 1 from bb b2 where b2.code=a1.code);
      

  2.   

    --merge into
    merge into AA a using BB b on(a.code = b.code)
    when matched then update set a.desc=b.desc_cn--
    update AA a set desc=(select desc_cn from BB b where  a.code = b.code)
      

  3.   

    update aa a1
    set a1.desc=(select b1.desc_cn from bb b1 where b1.code=a1.code)
    where exists ( select 1 from bb b2 where b2.code=a1.code);