假设有表A,表B,
表A 中数据有:                  表B 中数据有:
ID     name                 ID     name   
 
001    张三                   001     小小
002    李四                   002     左左
003    王五                   003     右右
004    爱情
...    在这样的两张数据表中,怎么实现将表A字段name变成表B数据中对应的相关值,它们关联的条件是ID字段
用SQL语句实现。

解决方案 »

  1.   

    FYI: 问题9
    http://topic.csdn.net/u/20081002/00/f8d90ba2-e2bb-412a-a0c5-1b6d518fc22a.html
      

  2.   

    update A a set a.name=(select b.name from B b where a.id=b.id)
      

  3.   

    难道LZ的A、B表不是使用ID做主健的,如要实现的话必须保证select b.name from B b where a.id=b.id
    中记录对任一a.id记录唯一,忽略业务的话可以加上and rownum<2
      

  4.   

    我现在的业务需求是这样的,其实表B是记录修改之前的状态,而表A是记录修改后的记录,现在要把表A中已修改了的记录还原。
    怎么实现SQL.
      

  5.   

    Update A Set Name = b.Name
    from A,B Where A.ID=B.ID;
      

  6.   

    你写的这个SQL语句我试了一下,提示语法有问题,好像没有这样用update的。
      

  7.   


    update A a
       set a.name = (select b.name from B b where a.id = b.id)
     where exists (select 1 from B b where a.id = b.id)