I saw the companions of the Messenger of Allah ﷺ rejoice over something more than I had ever seen them rejoice over anything else. A man asked, "Messenger of Allah, what about a man who loves another man for the good deeds he does, though he himself does not do the like of them?"The Messenger of Allah ﷺ replied, "A person will be with those he loves."
رأيت أصحاب رسول الله ﷺ فرحوا بشيء لم أرهم فرحوا بشيء أشد منه، قال رجل: يا رسول الله، الرجل يحب الرجل على العمل من الخير يعمل به ولا يعمل بمثله، فقال رسول الله ﷺ: المرء مع من أحب.
Abu Dawud (5127) reported it from Wahb bin Baqiya, Khalid narrated to us, from Yunus bin Ubayd, from Thabit, from Anas bin Malik, who said, and he mentioned it. Its chain of transmission is sahih.Ahmad (12625) reported it through another route, from Hammad, from Thabit, in abridged form.