Sahih Muslim Book 6, Hadith 81
A person entered the mosque, while the Messenger of Allah (ﷺ) was leading the dawn prayer. He observed two rak'ahs in a corner of the mosque, and then joined the Messenger of Allah (ﷺ) in prayer. When the Messenger of Allah (ﷺ) had pronounced salutations (he had concluded the prayer), he said: O, so and so, which one out of these two prayers did you count (as your Fard prayer), the one that you observed alone or the prayer that you observed with us?
The dawn prayer had commenced when the Messen- ger of Allah (ﷺ) saw a person observing prayer, whereas the Mu'adhdhin had pronounced the Iqama. Upon this he (the Holy Prophet) remarked: Do you say four (rak'ahs) of Fard in the dawn prayer?
When any one of you enters the mosque, he should say:" O Allah! open for me the doors of Thy mercy" ; and when he steps out he should say: 'O Allah! I beg of Thee Thy Grace." (Imam Muslim said: I heard Yahya saying: I transcribed this hadith from the compilation of Sulaiman b. Bilal.)