title: I have to loop through 9600 DISTINCT Domains in query 1 and Update an id in a second table in Query 2
body: <p>The query takes forever to update all Domains in the second table.</p>
  <p>Maybe there is a more efficient way to approach this?</p>
  <pre><code>$mysqli = new mysqli(&quot;localhost&quot;,&quot;xxxx&quot;,&quot;xxxx&quot;,&quot;xxx&quot;);
  
  if ($mysqli -&gt; connect_errno) {
    echo &quot;Failed to connect to MySQL: &quot; . $mysqli -&gt; connect_error;
    exit();
  }
  
  // Perform queries
  $result = $mysqli-&gt;query(SELECT DISTINCT dom FROM pmcts_mt_pipeline_details);
  
  $rows = $result-&gt;fetch_all(MYSQLI_ASSOC);
  foreach ($rows as $row) {
  $dom = $row['dom'];
  $mysqli-&gt;query(&quot;UPDATE pmcts_email_marketing_companies_pharma_all_unique SET id_ind_mailer=1 WHERE email_dom='$dom' AND (mailerdaemon=0 AND mail_excluded=0 AND unsubscribe=0 AND changeto=0)&quot;);
  }
  </code></pre>