It's been a few days I'm trying to understand how inner join works.
I have two simple tables (family bonds):
- "persons" (id, fname, lname)
- "relationships" (parent/child)
I learned how to get all parents of children
SELECT p.firstname, p.lastname, c.firstname, c.lastname
FROM persons p
INNER JOIN relationships ON p.id = relationships.parent
INNER JOIN persons c ON c.id = relationships.child;
What about getting all the grand parents of children instead?
Is it just an adjustment to that query or is it more involved? It seems to me that I should apply the same query to the query (a one time recursiveness) but I don't see how.
Thanks for your guidance.
PS: inner joins are easy to understand on paper but very hard for me to use because I'm used to procedural algorithms in order to create scripts but inner joins are not procedural at all in the way they should be approached. So I'm trying to analyse use cases to get used to them