Perhaps something like this? (Haven't tested so might not work) with recursive parents (id, parentId, name, found_what_i_want) as ( select *, false from export where id = 60363923 union all select export.*, export.id > 60363923 as found_what_i_want from export inner join parents on export.id = parents.parentId where not found_what_i_want ) select id, parentId, name from parents where found_what_i_want;