Code:
data in myTable

(id) mom geo

(0) 0 earth
(1) 0 North America
(2) 1 America
(3) 0 Europe
(4) 2 L.A.
(5) 2 New York
(6) 5 Manhatan
(7) 3 France
(8) 7 Paris
I have data in myTable like the above.

When myVariable is (2) ,
the query below produces all kids of the record (2).
Code:
query

select t1.id, t1.mom, t1.geo
  from myTable t1   
 
  join myTable t2
  on t1.mom = t2.id 
 
  where  t1.mom = #variables.V# or
            t2.mom = #variables.V# 
        order by id

result

(4) 2 L.A.
(5) 2 New York
(6) 5 Manhatan
Instead of the kids, I like to produce ancesters of the record(2) and the record(2) itself.

The following trial code seems not to work as I want.
Code:
trial code

select t1.id, t1.mom, t1.geo
  from myTable t1   
 
  join myTable t2
  on t1.id = t2.mom 
 
  where  t1.id = #variables.V# or
            t2.id = #variables.V# 
        order by id

result of the trial code

(1) 0 North America
(2) 1 America
(2) 1 America

 my target result

(0) 0 earth
(1) 0 North America
(2) 1 America