Reducing Disk IO by data reduction via MySQL aggregate functions

On one of my past hobby projects I had thousands of data points being generated. As I was only interested in the most recent value for each instance, I had a nightly cron job reduce the data, but my database got too large and kept triggering the IO rate alarm. By using the aggregate function MAX on mysql_fetch_assoc I deleted instances that hadn’t been active in 30 days:

$query = mysql_query("SELECT Id, MAX(last_action) FROM Group GROUP BY Id");
$count = mysql_num_rows($query);
if ($count > 0) {
while ($row = mysql_fetch_assoc($query)) {
$lastContact = $row['MAX(last_action)'];
$Id = $row["Id"];
if ($lastContact < (time() - $goBack30Days)) {
mysql_query("DELETE FROM Group WHERE userId='$Id' ");