Help for this page
select a.* from table_name a ... ) b on (a.distance = min_dist and a.service_id = min_id);
/is not a guru //tried it and it worked for me