title: How to avoid executing mysql queries in nested loop?
body: <p>I'm having a bit of a problem with a task I was assigned.</p>
  
  <p>I have this old phpmynewsletter database (MySQL backend).</p>
  
  <p>Basically all emails are saved in a table with this structure:</p>
  
  <pre><code>    email   varchar(255)
      list_id int(11)
      hash    varchar(255)
      disclaimer1 tinyint(1)
      disclaimer2 tinyint(1)
      gender  char(1)
      dob date
      region  varchar(50)
  </code></pre>
  
  <p>So one same email can be present several times in the table, this is, subscribed in different newsletters (identified by <strong>list_id</strong>)</p>
  
  <p>What I need to do is update the records so the fields <strong>disclaimer1</strong>, <strong>disclaimer2</strong>, <strong>gender</strong>, <strong>dob</strong> and <strong>region</strong> for a specific <strong>list_id</strong> are the same for the same <strong>email</strong> registered with other list_id's.</p>
  
  <p>For example:</p>
  
  <pre><code>    email: email1(at)gmail.com
      list_id: 1
      disclaimer1: 0
      disclaimer2: 0
      gender: M
      dob: 1975-05-02
      region: Portugal
  </code></pre>
  
  <p>and </p>
  
  <pre><code>    email: email2(at)gmail.com
      list_id: 33
      disclaimer1: 1
      disclaimer2: 0
      gender: M
      dob: 1975-05-02
      region: Portugal
  </code></pre>
  
  <p>How do I update the record with list_id 33 with the correct values from record with list_id 1?</p>
  
  <p>I'm using PHP and I believe that running updates queries in loops is bad practise. The table has around 610000 records.</p>
  
  <p>Hope somebody can give me some insight on how to accomplish this task.</p>
  
  <p>Thanks,
  Mário</p>