WITH tab AS( SELECT * FROM table1 WHERE Id='9' UNION ALL SELECT * FROM tab,table1 WHERE table1.Id=tab.ParentId ) SELECT * FROM tab;