update a set name=(select max(name) from b where b.id=a.id)
where exists(select 1 from b where b.id=a.id);

解决方案 »

  1.   

    谢谢
    能解释一下吗?
    在这里MAX()的作用是什么?不用就不行
    为什么要EXISTS呢?不用可以吗
      

  2.   

    应该是假设了你的A,B表是1:M的关系吧
      

  3.   

    不行,如果不是一对一关系的话,一行数据有两行数据对应,应该更新哪一个呢?所以肯定不行。
    exists 是防止 将没有对应关系的数据 更新 为null.这样写是必需的。
      

  4.   

    应该也可以
    update a set name=(select name from b where b.id=a.id and rownum = 1)
    where exists(select 1 from b where b.id=a.id);
      

  5.   

    update a set name=(select max(name) from b where b.id=a.id)
    where exists(select 1 from b where b.id=a.id);
    按照上面
    有错误,说什么不能更新表A,有NULL