title: Update a table from another table
body: <p>I want to update a field based on another table field. The table is like this:</p>
  
  <pre><code>TABLE A
  SID  SMONTH  STID VID  VVID
  1    201312   s10  v5    ?
  2    201312   s10  v5    ?
  1    201312   s11  v7    ?
  2    201401   s11  v7    ?
  1    201312    s1  v9    ?
  2    201401    s1  v9    ?
  1    201312    s1  v60   ?
  1    201312    s1  v71   ?
  </code></pre>
  
  <p>In the above table A , i need to update VVID column with the VVID from the below table B.</p>
  
  <pre><code>TABLE B
  VVID   STID  VID   WEIGHT
  v1     s10   v5    0.5
  v2     s10   v5    7.5
  v1     s11   v7    1.5
  v2     s11   v7    6.5
  v1     s1    v9    5
  v2     s1    v9    5
  v1     s1    v60   5
  v1     s1    v71   5
  </code></pre>
  
  <p>In the above table B , VVID is generated based on three fields STID , VID and WEIGHT . But in the table A , i dont have WEIGHT field. So if i use the below code i am getting "single row query returns more than one row" error.</p>
  
  <pre><code>UPDATE  A
  SET VVID = (SELECT distinct VVID
            FROM  B
            WHERE B.STID = A.STID and B.VID = A.VID  ) 
  </code></pre>
  
  <p>Please give me suggestions.</p>
  
  <p>Thanks 
  Sathish</p>