I'm using the query below multiple times on one page. As table1 grows, the queries slow down significantly.
Is there a better way to organize this? Am I gumming up the query somehow? Is there a faster way to query this data all together?
Thanks for any advice or guidance...
$sql = $pdo->query('
SELECT AVG(table1.VAR1), table1.ID, table2.VAR2, table2.VAR3, table2.VAR4
FROM table1
LEFT JOIN table2 ON table1.ID = table2.ID
GROUP BY table2.VAR2
ORDER BY AVG(table1.VAR1)
DESC
LIMIT 5');
foreach ($sql as $row) {
//echo results }
Im running PHP 5.2.4 and MySQL 5