Relate MYSQL table

1

I am developing a system for a Church. I have a people registration table, however I need to relate this table to myself. I want to relate in this same table everyone who has any kinship and display a family screen.

Next: Register 6 people with them: A , B , C , D , E and F . Suddenly, I find that B is the parent of E . The person A is coined of B and prime of C . How do I relate this?

The idea is when I select a person, to be able to list all the people connected to it. Father, mother, cousins, ... the difference is that everyone is on the same table.

    
asked by anonymous 20.01.2017 / 04:10

1 answer

1

A good suggestion would be to create another table, where you could store the relationship between these people,

For example:

CREATE TABLE Parentesco(
  id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  id_pessoa1 INT(6),
  id_pessoa2 INT(6),
  parentesco VARCHAR(30)
)

Joining (Joins) to get the desired relationships. This gives you greater control, scalability, and integrity. Making you can have the relationship from N to N.

    
21.01.2017 / 22:45