I'm writing a query to get the number of sessions created each day for the past 90 days. I'm currently using a prepared statement to do this - looks something like this:for($n = 0; $n < 90; ++$n){    $days[] = $n;}$st = $this->db->prepare(    SELECT *     FROM `sessions`     WHERE DATE(sessionStart) = DATE_SUB(CURDATE(), INTERVAL :n DAY));$bind = array(':n' => null);$data = array();foreach($days as $day){    $bind[':n'] = $day;    $st->execute($bind);    $data[$day] = $st->rowCount();}Would my code perform better using either of these?This code, which is essentially running 90 separate queriesRunning one query to return everything from the sessions table and then sorting the results in PHP
Returning the number of records per day
php;performance;beginner;mysql;pdo
Aside from @Sumurai8 recommendations, the sql query can be indeed complexified a bit to return all the results in one go:SELECT DATE_FORMAT(`sessionStart`, '%Y-%m-%d') AS `day`, COUNT(*) AS `sessions`FROM `sessions` WHERE     DATE(`sessionStart`) BETWEEN DATE_SUB(CURDATE(), INTERVAL 90 DAY) AND CURDATE()GROUP BY    `day`ORDER BY    `day`It only needs to be executed once, and then iterated over the result set using your favorite FETCH_XXX method.