WITH RECURSIVE result(id, routename ,routeurl,typeid ,parentid) AS (SELECT id, routename ,routeurl,typeid ,parentid FROM auth_route WHERE id = 1 UNION ALL SELECT i.id, i.routename ,i.routeurl,i.typeid ,i.parentid FROM auth_route i JOIN result ON i.parentid = result.id) SELECT * FROM result