Sep 23, 2018 06:15 AM
Hi everyone,
I have a table that has a list of people. There’s a field called “parents”.
I want to create a view on that table that shows only people without children. To do that, I’d use a formula that checks if the person is present on the “parents” field of any record. If the result is false, it means the person is without children.
The problem is that I can’t figure out how formulas can use values from other records. I’m proficient in SQL and to do that I would use the clause "WHERE NOT EXISTS ".
Does anyone have an idea on how to do that?
Sep 24, 2018 06:41 AM
I think you need an extra Table (maybe Parenthood), because you can’t get the number childs from the same table, I mean with a Lookup.
Sep 24, 2018 06:49 AM
An example
People:
Relations:
And then you could create a View with the desired Filter:
Sep 29, 2018 04:06 AM
Thanks Elias for taking the time to explain this to me!
Actually this is a very clever trick, but I fear it stops working if I also want grandparents and grandchildren. We would need to add another level of indirection (another table).
That’s because Airtable lacks what in relational databases are called “self joins”, and so recursion is not possible.
Sep 29, 2018 06:39 AM
Easy! The relation is the same, you only need to add fields for the needed levels.
Sep 30, 2018 05:05 AM
Airtable does support self-joins. However, it doesn’t support reciprocal self-joins, so you’d have to make explicit links both ways. Also, neither of the traditional linked-record field types (rollup, lookup) can be used on self-joins, so you’re limited to retrieving the names of the linked records — which in your case looks as if might be sufficient.
Oct 08, 2018 03:52 AM
@Elias_Gomez_Sainz I just noticed a thing while recreating your example.
Are these steps correct?
(1) adding Marie, Peter, Sandra in People
table
(2) adding Sandra > Marie
and Peter > Marie
records in Relations
table
(3) modifying parents
field of Marie in People
with a reference to records Sandra > Marie
and Peter > Marie
(4) modifying children
field of Peter and Sandra in People
, adding a reference to Sandra > Marie
and Peter > Marie
I feel there’s duplication of information while performing steps 3 and 4, because the relationship between these three people is already expressed in step 2.
This could lead to inconsistencies in information stored in the database if someone makes a mistake or forgets steps 3 and 4.
Am I forgetting something?
Oct 24, 2018 01:48 AM
Has anyone read this post?
Oct 24, 2018 07:34 AM
I did just now :winking_face:
Airtable allows lookups on self-joins now:
This should eliminate the need to perform steps 3 and 4 above. Instead, perform a lookup One way or the other, either to see who the parents are (if you joined children to parents), or to see who the children are (if you joined parents to children).
Oct 25, 2018 08:18 AM
@Jeremy_Oglesby that’s great news! Airtable has made a significant step in the right direction with this feature!