title: MYSQL/PHP Unable to save result set
body: <p>I am running a PHP script which basically tries to find matching names from MYSQL database and then assigns the same number to records with identical names. </p>
  
  <p>My problem is that the number of records are around 1.5 million. The script always  runs for about 14 hours every time and gives this error : mysql_query unable to save result set in xx on line xxx. and phpmyadmin gives this error #2008 out of memeory </p>
  
  <p>Here is my php code</p>
  
  <pre><code>mysql_query("SET SQL_BIG_TABLES=1");
  
  $res = mysql_query("SELECT company_name, country, id FROM proj")
         or die (mysql_error());
  
  while ($row = mysql_fetch_array($res, MYSQL_NUM)) {
      $res1 = mysql_query("SELECT company_name, id FROM proj WHERE country='$row[1]'"+
            "AND id&lt;&gt;'$row[2]'") or die ("here".mysql_error().mysql_errno());
  
      while ($row1 = mysql_fetch_array($res1, MYSQL_NUM)) {
            //My calculations here 
      }
  }
  </code></pre>