You would have to merge the two routines for building the related-categories and the sub-categories together. Rather than outputting them, you'd want to find all the related-categories, and change the name to an "name@" format, then sort the two lists of categories together, then output them to the &load_template command in that order, and put them into one variable something like $all_subcats.
I can see a potential problem with this, but it could be fixed by inserting another tag into the "related" records $rec->{is_related}=True for any category that was related, then sort them on name, then before sending to the &load_template command you checked to see if (is_related) then change_name, else, just send.
http://www.postcards.com FAQ:
http://www.postcards.com/FAQ/LinkSQL/