let's say I have a column named "parent" that references the ID column from the same table. so it can empty or a number. if it's empty it means that the record has no parent.
Example:
ID name parent
1 A
2 B 1
3 C 2
4 D 2
to get the ancestor of C I make two queries:
SELECT parent FROM table WHERE id = 2
SELECT parent FROM table WHERE id = 1
then I get empty parent so I know 1 is the ancestor.
I was wondering if it's possible to do this in a single query :)