title: MySQL: Updating id value in one table from another table
body: <p>I have a table <code>table1</code> <code>o_id</code> as <code>PK</code>,  <code>ipaddress</code>, <code>b_id</code></p>
  
  <pre><code>o_id    ip              b_id
  9205    10.10.10.10     null
  9206    10.10.10.11     null
  9207    10.10.10.12     null
  </code></pre>
  
  <p>---more than 1000 rows</p>
  
  <p>I have another table <code>table2</code> <code>id</code> as <code>PK</code>,  <code>ipaddress</code>, <code>b_id</code></p>
  
  <pre><code>id      ip              o_id
  18356   10.10.10.10     null
  18357   10.10.10.11     null
  18358   10.10.10.12     null
  </code></pre>
  
  <p>---more than 1000 rows</p>
  
  <p>Now, if <code>ipaddress</code> matches in both tables, then I want to update both tables such that <code>table2.o_id = table1.o_id</code> and <code>table1.b_id = table2.id</code></p>
  
  <pre><code>update table1  
  set b_id = table2.id
  where ip = table2.ip
  </code></pre>
  
  <p>Here I want to update <code>o_id</code> in second table from the <code>o_id</code> in first table.
  I also want to update <code>b_id</code> in first table from <code>id</code> in second table.</p>
  
  <p>Is above query correct? there a way to update both tables in single query?</p>