title: update data based on another table
body: <p>I have a user table with following fields</p>
  
  <pre><code>id           int
  name         varchar
  dob          date/time
  </code></pre>
  
  <p>Now, I have another table called user_map table, with 2 fields</p>
  
  <pre><code>oldid        int
  newid        int
  </code></pre>
  
  <p>user_map table is used for storing user id mapping, field 'oldid' is user's old id (which is current user id from user table), and 'newid' is user id going to be assigned</p>
  
  <p>I need a single update query, which can update user id for all users in user table</p>
  
  <p>How should it work? Well, for each id in user table, there will be only 1 record matching in user_map table.</p>
  
  <p>id from user table matches oldid from user_map table, and it should be replaced by newid</p>
  
  <p>For example (ignore dob field please)</p>
  
  <p>user table</p>
  
  <pre><code>       id                   name                     dob
          1                    aaa                     0000-00-00 00:00:00
          2                    bbb                     0000-00-00 00:00:00
          3                    ccc                     0000-00-00 00:00:00
  </code></pre>
  
  <p>user_map table</p>
  
  <pre><code>      oldid       newid
          1           6   
          2           7   
          3           8   
  </code></pre>
  
  <p>After query, user table should look like</p>
  
  <p>user table</p>
  
  <pre><code>       id                   name                     dob
          6                    aaa                     0000-00-00 00:00:00
          7                    bbb                     0000-00-00 00:00:00
          8                    ccc                     0000-00-00 00:00:00
  </code></pre>
  
  <p>how can I achieve this? is it possible in 1 query only?</p>