in reply to Help with manipulating data from a database??

Two SQL queries.
SELECT DISTINT service_ID from ..... Fetch into array and loop... foreach (serviceID) { SELECT stop_reference, distance from XXX WHERE service_ID = :p1 AND distance = (SELECT min(distance) from XXX where service_id = : +p1) }
I'm sure some SQL guru can wrap this all into one SQL query. In Oracle, you could use PL/SQL to get this, too. But even in pure SQL you should be able to do this without a loop. I'm just not an SQL guru. :(