Answer the question
In order to leave comments, you need to log in
Does the load on the database increase if you nest one query in another?
I have around this:
$z = 0;
$a= mysql_query("SELECT h
FROM b
");
while ($c=mysql_fetch_array($a))
{
if ($z >10) break;
$d= mysql_query("SELECT g
FROM e
WHERE h = $c[h]
");
while ($f=mysql_fetch_array($d))
{
echo $f['g'];
$z++;
}
}
$m= array();
$z = 0;
$a= mysql_query("SELECT h
FROM b
");
while ($c=mysql_fetch_array($a))
{
array_push($m, "$c[h]");
}
foreach ( $m as $mo ) {
if ($z >10) break;
$d= mysql_query("SELECT g
FROM e
WHERE h = $mo[h]
");
while ($f=mysql_fetch_array($d))
{
echo $f['g'];
$z++;
}
}
}
Answer the question
In order to leave comments, you need to log in
Your task is solved with one query:
SELECT g FROM e
INNER JOIN b ON b.h = e.h
https://habrahabr.ru/post/31129/
everything is not so simple/unambiguous there, look at Mail ru lectures on Muskul and Aksenov's lectures (author of Sphinxsearch), there is no universal recipe for comparable tasks - and joins are not so resource-intensive, and muscle he can choose a non-optimal path himself (hence the indication of specific indexes), etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question