Can I select the rows that have the greatest Column A values compared to all other rows which have identical columns B in MySQL?
SELECT id, MAX(`time`) AS `time`
FROM sourcetable
GROUP BY id;

PS. Stop thinking in iterations, think in datasets.