Relate MYSQL Table

Asked

Viewed 107 times

1

I am developing a system for a Church. I have a table of registration of people, but I need to relate this table to itself. I want to list in this same table everyone who has some kinship and display a screen of families.

Next: Register in her 6 people being them: A, B, C, D , E and F. Suddenly, I find that the person B is the person’s father E. The person A is sister-in-law of B and cousin of C. How do I relate this?

The idea is when I select a person, I can list all the people connected to it. Dad, Mom, cousins, ... the difference is they’re all on the same table.

1 answer

1

A good suggestion would be you 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)
)

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

  • Better even, I would only create one more table of the types of kinship, and with that, in this table Kinship instead of having kinship would have type_kinship, would be more normalized the database

Browser other questions tagged

You are not signed in. Login or sign up in order to post.