If two people come in and they find that there is only enough room for one man in the first or second row, then they should stand together, because if one of them joins the row the other will be left standing on his own. In this case it is better for them to pray standing together behind the row. But if they find enough room for two men in the row, then they should both stand there, and not stand behind the row on their own, because that is contrary to the Sunnah. The Prophet (peace and blessings of Allaah be upon him) encouraged completing the rows one by one, starting with the first. But if it so happens that they did that, then their prayer is valid because neither of them stayed on his own away from the other. End quote.
Majmoo’ Fataawa Ibn ‘Uthaymeen (15/207).