i need to find a quicker way to loop a three level deep query.
i got my customer, products and selling_date tables in a symfony2 project.
i need to generate the pricelist for each product, for each customer of each selling_date.
Normally i use to make a nested query where on each customer i loop each product on which i loop each list, so it looks like this
$c = "select * from customer"
loop each cust
$p = "select * from product "
loop each prod
$l= "select * from list "
CREATE THE PRICE LIST RECORD
end loop
end loop
the problem is that i got 1000 customers, 20k products, 4 selling_date. as you may notice the amount of iterations is too big. so it goes on timeout, and even if i set an higher timeout, it requires a lot of time (consider that this "function" must be executed at least twice time a day)
is there a best practice to avoid this?
Thank you in advance