Topic: Whether it is possible to make a recursion in a SQL query?
The circuit simplified, but as a whole so:
There is a table "a load card", characterizing a load and its driving. The given card can be type "car", "coach" and "warehouse".
Weeding, say, the such:
id; id_ - The load (the link to the same card) whence came; Type (' auto ', ' wagon ', ' placement '); id_ Either id_ or id_; Load weight;
For example, any load arrived the car, then was moved on a warehouse. It is required to define transport on which there arrived a load. It is simple - we have a load card in a warehouse, we address to a field id_ (it is the link to the same card) and we look its type - ' auto '. Across the field id_ we define the car.
But the situation becomes complicated, if a load some times moved from a warehouse on a warehouse the chain of cards where the car card, then some cards of a warehouse to last will be the first, accordingly, is formed. And it is necessary to define the car which there arrived a load initially. And here it is necessary to untwist all chain, yet you will not meet a vehicle.
Whether it is possible to make it by means of storable function or procedure? And how to combine a procedure call in a SQL query if for example there the list of cards of a warehouse, and it is necessary to deduce the list of vehicles for them - any will be defined at once, and others need to be pulled out through a recursion, and to produce this all one list.