There are 2 tables
1) Contacts
id | Name
2) Relatives
id | Contact1 (контакт первый) | Contact2 (второй) | Family (кем приходится)
There can be any number of connections per contact. It is necessary to derive contacts when outputting, if this contact has related relationships.
SELECT contact.id, contact.name, COUNT(fam.id) FROM contact LEFT JOIN fam on contact.id = fam.contact or contact.id = fam.contact2 GROUP BY fam.id ORDER BY contact.name
There is a problem: everything works, but in the base 743 contacts, and a maximum of 50 is output.