Can I select the rows that have the greatest Column A values compared to all other rows which have identical columns B in MySQL? Perhaps not the clearest explanation.
I have this table:
+-----+------+
| ID  | Time |
+-----+------+
|  1  |  5   |
|  1  |  2   |
|  1  |  4   |
|  2  |  1   |
|  2  |  5   |
|  3  |  6   |
+-----+------+

I want the row with ID=1 that has the greatest Time compared to other rows where ID=1.  The same with WHERE ID=2, etc.  So essentially &quot;get me all the rows that have greatest Time as compared to other rows that have the same ID as them&quot;.  So the results in this case would be:
+-----+------+
| ID  | Time |
+-----+------+
|  1  |  5   |
|  2  |  5   |
|  3  |  6   |
+-----+------+
SELECT id, MAX(`time`) AS `time`
FROM sourcetable
GROUP BY id;

PS. Stop thinking in iterations, think in datasets.