I\'m pretty new to SQL, trying to wrap my head around it, but it\'s getting a little confusing. Here\'s a simplified version of what I\'m working with.
I have this
This is without JOIN statement, but as a SQL learner, I find it as easier:
For grandchildren:
SELECT grandparent.name AS Grandparents, grandchild.name AS Grandchildren
FROM people AS grandparent, people AS parent, people
AS grandchild WHERE grandchild.parent_id = parent.id
AND parent.parent_id = grandparent.id;
For children:
SELECT parent.name as Parent, child.name AS Child
FROM people AS parent, people AS child
WHERE child.parent_id = parent.id AND parent.parent_id = 0;
And for all children-parent pairs:
SELECT parent.name as Parent, child.name AS Child
FROM people AS parent, people AS child
WHERE child.parent_id = parent.id;
It took me a while, but it was fun :D