Subject Re: [ib-support] Re: sql problem
Author Svein Erling Tysvaer
Sorry for not answering you with your original question Duilio, I
considered answering, but forgot.

Your current solution is ambiguous, if it works you're just lucky! You
don't say which table to_id should come from, the engine may choose either
a or b. A better solution would be

for select distinct to_id from ATable a
where to_id=:aId //itself
or exists(select 1 from ATable b where a.to_id=b.fm_id and b.to_id =
:ald) //one level down
or exists(select 1 from ATable b where a.to_id=b.fm_id and
exists(select 1 from ATable c where b.to_id = c.fm_id and c.to_id = :ald))
//two levels down
into id

HTH,
Set

At 13:45 17.02.2003 +0000, you wrote:
> > a table is structured like a linked list:
>
>I found the solution.
>
>I enclose it below, in the case somebody is interested.
>
>Duilio Foschi
>
>CREATE PROCEDURE PathBack(aId integer)
>RETURNS
> (id integer )
>as
>begin
> for select distinct to_id from ATable a, ATable b where
>a.fm_id=b.to_id or to_id=:aId
>into id
> do
> begin
> suspend;
> end
>end;
>
>
>
>
>
>
>To unsubscribe from this group, send an email to:
>ib-support-unsubscribe@egroups.com
>
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/