Dynamic SELECT condition

Поиск
Список
Период
Сортировка
Искать

Dynamic SELECT condition

От:
"Victor Yegorov" <viy@pirmabanka.lv>
Дата:
Hello.

I'd like to know, is it possible to use returned data set values as
condition at runtime?

Here comes the details.
I have one table which links objects of various types into trees. Say, it has
5 rows:
parent_id | child_id
-----------+----------1         | 21         | 33         | 43         | 54         | 6
Each parent_id and child_id are primary keys in some other tables (don't matter
which, with object details).

Say, I'd like to show user a tree for object_id = 3 on the web.

Is it possible to get the following result set with one SQL request:
parent_id | child_id
-----------+----------3         | 43         | 54         | 6
I mean, I know the id of a root object, it's 3. If I'll extract with
condition parent_id = 3, then I'll get only 2 rows. I'd like to have a
recursive result set - while there are records in the table for which
count(next_level_parent_id == this_level_child_id) > 0, select parent_id, child_id.

I hope you'll understand my problem.

Thanks in advance.

--
Victor Yegorov
FAQ