One who prays for his friend while he himself needs the same thing is answered first.
Sefer HaMidos, Prayer, Part I §6