Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Faster update query for big table

I have a pretty large database which was imported using the csv 'LOAD DATA INFILE' method. Some cells though need to be manipulated and unfortunately i cant do that during the import. I have to do it afterwards since PHP is much easier to play with, not to mention that there are other table cells that need to be changed which is impossible to do with mysql commands. One example of these type of manipulations is the 'Telephone' cell. I have to break the telephone number then update separately 2 different cells of the same row. For example:

$myQ = my_db_query("SELECT companyId, Telephone FROM companies WHERE 1");
while ($row = my_db_fetch_array($myQ))
{
    if($row["Telephone"] != ""){
        $Telefon_area = "";
        $Telefon_num = "";
        $pieces = explode(" ", $row["Telephone"]);
        $Telefon_area = trim( $pieces[0] );
        $Telefon_num  = trim( $pieces[1] );
        my_db_query("UPDATE companies SET `Telefon_area` = '$Telefon_area', `Telefon_num` = '$Telefon_num' WHERE `companyId` = ".$row["companyId"]);
    }
}

The problem i am facing with this approach is that (although i've indexed column Telephone), it is veeeery slow, because i am updating 1.5mil entries.

Is there a faster way of doing this ?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!