title: MySQL update with select from another table
body: <p>I've got 3 tables.
  Companies, Kommuner and Fylker.</p>
  
  <p>The companies table have an empty field <code>forretningsadresse_fylke</code> but an other field <code>forretningsadresse_kommune</code> with a value. </p>
  
  <p>So basically, I need to fill in <code>forretningsadresse_fylke</code>, based on the value of <code>forretningsadresse_kommune</code>.</p>
  
  <p>Now, the value of <code>forretningsadresse_kommune</code> and the value I want for <code>forretningsadresse_fylke</code> is stored in the Kommuner and Fylker tables.</p>
  
  <p>So I wrote this query, but that doesn't seem to work because after 600 seconds the "MySQL server goes away".</p>
  
  <pre><code>UPDATE companies, fylker, kommuner
  SET companies.forretningsadresse_fylke = (
      SELECT fylkeNavn 
      FROM fylker 
      WHERE fylker.fylkeID = kommuner.fylkeID
  )
  WHERE companies.forretningsadresse_kommune = kommuner.kommuneNavn
  </code></pre>
  
  <p>Here is what the Kommuner and Fylker tables look like.</p>
  
  <p>Kommuner Table</p>
  
  <p><a href="https://i.stack.imgur.com/r5ckf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r5ckf.png" alt="enter image description here"></a></p>
  
  <p>Fylker Table</p>
  
  <p><a href="https://i.stack.imgur.com/9f8IV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9f8IV.png" alt="enter image description here"></a></p>
  
  <p>Companies table
  <a href="https://i.stack.imgur.com/3CDLI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3CDLI.png" alt="enter image description here"></a></p>
  
  <p>companies Table</p>
  
  <pre><code>            | forretningsadresse_fylke  | forretningsadresse_kommune |
              |===========================|============================|
              |                           |                            |
              |                           |                            |
              |                           |                            |
              |                           |                            |
              |                           |                            |
              |                           |                            |
  </code></pre>
  
  <p>So I was wondering if there was something wrong with the query?
  Also, it might be good to mention, the table I try to update (Companies) has over 1 million rows.</p>
  
  <p>Thanks in advance!</p>