in reply to (OT?) Recursive sql queries?
Eg:
(Which is currently sitting around on my scratchpad, together with an iterative solution, using an SQL procedure, which is probably faster than using perl, let the database do the work.)Recursive SQL (DB2): (WITH X defines a temporary view) WITH trips(destination, route, totalcost) AS ((SELECT destination, destination, cost FROM flights WHERE origin = "SFO") UNION ALL (SELECT f.destination, t.route || ',' || f.destination, t.totalcost * f.cost FROM trips t, flights f WHERE t.destination = f.origin)) SELECT route, totalcost FROM trips WHERE destination = "JFK"; NB: There is no stop condition, so this will run indefinitely..
The recursion in DB2 works such that each recursion only 'sees' the results of the previous one.
Anyway, this rambling doesnt help if you dont have DB2, or anything that does such temporary views.. So the other possibility is a stroed sql procedure, assuming you can do those.
C.
|
|---|