I know that between two tables in a many-to-many relationship 'we need' (not mandatory but facilitates) a third table pivot which is what conventionally relates the ids of one to the ids of another. So far so good. So for example to make a gene tree? Would we have to create a pivot table for every two tables? Below is an image to illustrate a parent / child relationship where there is a pivot table in the 'support':
Tables: pais
, filhos
, pais_filhos
respectively. And finally the INNER JOIN
between them
And now if we wanted to add a avos
table we would have to create another pivot to relate the ids of the parents to the ids of the grandparents? And then to add great-grandparents too? Or is there an 'easier' way to achieve this? That is, without 'needing' to create a pivot table for every two tables? I know I could not even use a pivot table , just get a separator between ids, for example in the children's table create a column id_pais
and insert the ids in the format 1|2
and grandparents would it be a ids_avos
column with 1|2|3|4
, and would it also do the same? It seems almost equally 'laborious' if we had tri, tetra, penta ... avos.
Is there another way that I did not mention here and I do not know to do this? What is the best way to do this?