At Sāvatthi.
"Just as elements, bhikkhus, beings associate and come together. The faithless associate and come together with the faithless; the unashamed associate and come together with the unashamed; the unwise associate and come together with the unwise; those with faith (confidence) associate and come together with those with faith (confidence); the conscientious associate and come together with the conscientious; the wise associate and come together with the wise.
Even in the past, bhikkhus, just as elements, beings associated and came together, the faithless associated and came together with the faithless; the unashamed associated and came together with the unashamed; the unwise associated and came together with the unwise; those with faith (confidence) associated and came together with those with faith (confidence); the conscientious associated and came together with the conscientious; the wise associated and came together with the wise.
Even in the future, bhikkhus, just as elements, beings will associate and come together, the faithless will associate and come together with the faithless; the unashamed will associate and come together with the unashamed; the unwise will associate and come together with the unwise; those with faith (confidence) will associate and come together with those with faith; the conscientious will associate and come together with the conscientious; the wise will associate and come together with the wise.
Even now, bhikkhus, at the present time, just as elements, beings associate and come together. The faithless associate and come together with the faithless; the unashamed associate and come together with the unashamed; the unwise associate and come together with the unwise; those with faith (confidence) associate and come together with those with faith; the conscientious associate and come together with the conscientious; the wise associate and come together with the wise.
Just as elements, bhikkhus, beings associate and come together. The faithless associate and come together with the faithless; the reckless associate and come together with the reckless; the unwise associate and come together with the unwise; those with faith (confidence) associate and come together with those with faith; those with moral dread associate and come together with those with moral dread; the wise associate and come together with the wise ... (and so on).
Should be expanded like the first round.
Just as elements, bhikkhus, beings associate and come together. The faithless associate and come together with the faithless; the unlearned associate and come together with the unlearned; the unwise associate and come together with the unwise; those with faith (confidence) associate and come together with those with faith; the learned associate and come together with the learned; the wise associate and come together with the wise ... (and so on).
Just as elements, bhikkhus, beings associate and come together. The faithless associate and come together with the faithless; the lazy associate and come together with the lazy; the unwise associate and come together with the unwise; those with faith (confidence) associate and come together with those with faith; the energetic associate and come together with the energetic; the wise associate and come together with the wise ... (and so on).
Just as elements, bhikkhus, beings associate and come together. The faithless associate and come together with the faithless; the forgetful associate and come together with the forgetful; the unwise associate and come together with the unwise; those with faith (confidence) associate and come together with those with faith; the mindful associate and come together with the mindful; the wise associate and come together with the wise ... (and so on).
In this discourse, the Buddha is sharing that beings associate and come together based on shared qualities and traits. As you grow and evolve your qualities through learning, reflecting and practicing the teachings, you also allow space for your existing relationships to upgrade as well as for new relationships to form based on your growing and evolving qualities.
Related Teachings:
The defining characteristic of living beings (SN 23.2) - Rādha asks the Buddha about a the term "being", and the Buddha explains in terms of craving for the five aggregates. He compares such craving to a child playing with sandcastles.
Four Bases of Supportive Relationships (AN 4.32) - Giving, kind speech, beneficial action and impartiality are the four bases of supportive relationships.