返回的值可能超過一行update A set a.money1=(select b.money2 from b where a.id=b.id and rownum=1);

解决方案 »

  1.   

    update A set a.money1=(select b.money2 from b where a.id=b.id);
    本身是没有什么问题的.
    除非money2中同一个ID对应了几个money2的自段.
    update a set a.money1=(select money2 from 
                   (select id,sum(money2) money2 from b group by id) b
                       where a.id=b.id)
    应该可以了.
      

  2.   

    update A set money1=b.money2 from B where B.id=A.id
      

  3.   

    哦,上面是SQL Server的语法,呵呵
      

  4.   

    谢过baojianjun(包子)先,应该没有返回多行,id是唯一的,a表有10000条记录,b表有50条记录,你给的语句也不好用
      

  5.   

    update A set money1=(select money2 from B where A.id=B.id);只要保证A.id和B.id都是唯一的,执行不会有问题的
      

  6.   

    SQL> update A set money1=(select money2 from B where A.id=B.id);已更新 4 個資料列.我的测试数据id=1,2,3,4没有问题
      

  7.   

    不过如果A中有id=5的数据而B中没有,A.money1会变成空
      

  8.   

    NinGoo(宁哥) :是的,我只希望更新a表中对应于b表有的数据被更新,b表没有而a表有的记录保持不变。怎么写sql?
      

  9.   

    update A set money1=(select money2 from B where A.id=B.id) where id in (select id from B)这样应该就不会有我上面说的问题了,呵呵
      

  10.   

    update A set a.money1=(select b.money2 from b where a.id=b.id);
    分析:
    1:如果A表中有数据,但是在B表中没有a.id=b.id的数据,那么,该条数据将被置为空。
    2:就是所讲的多值问题。就是满足a.id=b.id的数据有多条。
    可以修改为:
    update A set a.money1=(select max(b.money2) from b where a.id=b.id) where exists (select * from c where a.id=c.id);
      

  11.   

    好不容易能在oracle版回答个问题,居然给0分,呵呵