表A: 
Rid  productCode  
1   2 
2   3 A中productCode的值是唯一的 
表B 
id ProductCode Rid   
1  2           需更新的值 
2  1           需更新的值 
3  2           需更新的值 需求:表A中ProductCode与表B中的ProductCode是一对多的关系。 请教如何写sql将表A中的Rid值根据productCode更新到表B中rid字段。 

解决方案 »

  1.   

    update b set(rid)=(select rid from a,b where a.productCode = b.productCode)
      

  2.   

    update b set rid=(select a.rid from a,b where a.productCode = b.productCode)
      

  3.   

    update B set rid = (select rid from A where productCode = B.productCode and productCode in (select productCode from B)) 
      

  4.   

    update B set b.rid=(select a.rid from a where a.productcode=b.productcode and rownum=1)
      

  5.   

    update table2 a
    set rid=(select b.rid from table1 b where a.productcode=b.productcode(+)
    主要要有這個外連接才行的哦!