alexa
Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry

Query Optimization, changing the queries in the loop into a single processing query in SQL ?

Query Optimization, changing the queries in the loop into a single processing query in SQL ?

Try this:

 $applicantIds = \DB::select()->from( 'applicants' )->where( 'created_at', 0 )->execute();
$applicantApps = \DB::select( 'applicant_id', 'created_at' )->from( 'applicant_apps' )->where( 'applicant_id', 'in', $applicantIds)->execute();

$statement = '';
foreach ($applicantApps as $applicantApp) 
{
   $applicantId = $applicantApp['applicant_id'];
   $applicantCreatedAt = $applicantApp['created_at'];
   $statement .= "update applicants set created_at='$applicantCreatedAt' where id = '$applicantId';"
}

if ($statement) {
   \DB::query($statement)->execute();
} 

Two queries only will get you this.


324 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online