设cust表
cust_id    city_name
 1
 2
addr表
cust_id  city_name  
 1         北京
 1         北京
 2    上海
 2    上海update cust a set a.city_name=
(select b.city_name from addr b where b.cust_id=a.cust_id and rownum=1)addr表中有多条重复记录,随机取一条,
但结果得到cust表
cust_id    city_name
 1          北京
 2          北京

解决方案 »

  1.   


      1  update cust c set c.name=
      2* (select b.c_name from (select id,max(a.name) c_name from emp a group by id) b where b.id=c.id)
    SQL> /2 rows updated.SQL> select * from cust;        ID NAME
    ---------- --------------------
             1 hh
             2 gg
    分下组就可以了
      

  2.   

    有可能还需要用到WHERE EXISTS这个就要看你表中的数据了
      

  3.   

    update cust a set a.city_name=
    (select b.city_name from addr b where b.cust_id=a.cust_id and rownum=1)
    and rownum=1