I have a train lines table which looks like this:
The task is to get every possible destination from a given Start (recursively).
I've tried to do it like this:
with cte (st, nd) as(
select from1, to1
from RailwayTbl
where from1 = 'Berlin'
union all
select e.from1, e.to1
from RailwayTbl e join cte
on cte.nd = e.from1
)
select * from cte;
When executed, I got the following error:
The statement terminated. The maximum recursion 100 has been exhausted before statement completion. ((It is an infinite loop..))
And when I removed the all and used union only I got this error:
Recursive common table expression 'cte' does not contain a top-level UNION ALL operator.
Any ideas?
Thanks in advance!

text, so we can't test, but that looks like you have a multiple circular references. For example'Amsterdam'->'Berlin'->'Amsterdam'->'Berlin'->'Amsterdam'.... ->'Berlin'->'Amsterdam'... ->'Berlin'->'Amsterdam'... you get the idea