I'm not aware of MySQL supporting this feature. Microsoft does and calls
it "common table expression" (CTE). The UNION is necessary as this the
part that links the anchor query, Part1 of the UNION to the recursive
query, Part2. Part2 of the UNION must reference the produced temporary
table called "ReachableFrom" in your example. The Part2 query is put in
an internal loop constantly inserting new rows into the CTE and then
referencing them in the next loop. Once the loop no longer generates new
rows the CTE stops and the final query is executed.

Ed

-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Thufir
Sent: Wednesday, February 27, 2008 12:28 AM
To: mysql@lists.mysql.com
Subject: recursion

I'm reading "SQL for dummies" and one of the more interesting sections 
was on recursion.  The example query was something like:

WITH RECURSIVE
   ReachableFrom (Source, Destination)
   AS (SELECT Source, Destination
      FROM FLIGHT
   UNION
   SELECT in.Source, out.Destination
      FROM ReachableFrom in, FLIGHT out
      WHERE in.Destination = out.Source
   )
SELECT * FROM ReachableFrom
WHERE Source = "Portland";

I'm a bit thrown by the union.  Can this be simplified to:


WITH RECURSIVE
   ReachableFrom (Source, Destination)
   AS (SELECT Source, Destination
      FROM FLIGHT
   )
SELECT * FROM ReachableFrom
WHERE Source = "Portland";



thanks,

Thufir


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to