Using MySQL, I want to return a list of parents, from a table that has a field structure like this. ID,PARENTID,NAME (a standard parent-child hierarchy). I would like to tra
In this example we are checking 5 levels up:
select
t1.parentid, t2.parentid, t3.parentid, t4.parentid, t5.parentid
from
tableName t1
left join tableName t2 on t1.parentid = t2.id
left join tableName t3 on t2.parentid = t3.id
left join tableName t4 on t3.parentid = t4.id
left join tableName t5 on t4.parentid = t5.id
where
t1.name = 'thing3'