with a as ( select id,name,parentid from categories where id=53 union all select x.id,x.name,x.parentid from categories x,a where x.parentid=a.id ) select * from a
with a as ( select id,name,parentid from categories where id=53 union all select x.id,x.name,x.parentid from categories x,a where x.parentid=a.id ) select * from a