有2个表a,b(其实是一个多表关联的select语句)我要将a表中x栏位的值更新为b表的y栏位值a和b表中都有1万笔数据,并且id一一对应update语句怎么写?update a set a.x = 这里不会写(select ...) b where a.id = b.id虚心请教,谢谢

解决方案 »

  1.   

    update a t1
    set t1.x=(select t2.x from b t2 where t2.id=t1.id)
    where exists ( select 1 from b t3 where t3.id=t1.id);
      

  2.   

    update a t1
    set t1.x=(select t2.y from b t2 where t2.id=t1.id)
    where exists ( select 1 from b t3 where t3.id=t1.id);
      

  3.   

    update a set a.x =(select y from b where a.id=b.id)
      

  4.   


    --merge intomerge into a using b on(a.id = b.id)
    when matched then update set a.x=b.y