This is sort of a fundamental question about using CTEs. If I have a table with the following schema and data:Nodes----------id | name1 | node12 | node23 | node34 | node4Paths (these are unidirectional)---------from | to1 | 22 | 31 | 43 | 1
How can I write a query which figures out all nodes reachable from node2?If I do the following:with Route as ( select 2 as id union all select p.to as id from Route r, Paths p where r.id = p.from)select * from Route
I'll get infinite recursion.If I add one more WHERE clause and do with Route as ( select 2 as id union all select p.to as id from Route r, Paths p where r.id = p.from and not exists (select count(*) from Route r2 where r2.id = p.to))select * from Route
I'll get the error "Recursive member of a common table expression 'Route' has multiple recursive references."Is there any way to write a CTE for this scenerio?