Subject Re: [firebird-support] Re: Recursive Query
Author Lucas Franzen
Uwe,

> Thanks.
> I have revised the query as follows.
> SELECT DISTINCT *
> FROM Tbl T1 LEFT OUTER JOIN Tbl T2 ON (T1.ID = T2.Link)
> WHERE T1.Name LIKE 'ZAR%';
>
> And it now shows the main record and the child record however it shows the
> main record for every child record again even with distinct.

This CAN'T be achieved with a query, since there's no sql for sth. like
that (you can't pipe a query, meaning: you can't take the output from
your query and tell the query it should take this as input as long as
there are still records found).

If you want to have recursive queries to (for example) show kind of a
treeview, you HAVE to build a stored procedure that takes a starting
point, and while retrieving the records it will call itself over and
over again to get the records from the next level.

But be aware there's a limit of recursion depth, I just don't know the
value.
I do use a stored proc like this for retrieving the rigths that are
given to user groups within my db (not the standard fb rights (GRANT,
etc), but the rights the users have within the program. So this can be
shown in a treeview and easily managed recursively.)

Luc.