250
Part III: Storing and Retrieving Data 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’; The first time through the recursion, FLIGHT has seven rows, and REACHABLEFROM has none. The UNION takes the seven rows from FLIGHT and copies them into ReachableFrom. At this point, REACHABLEFROM has the data shown in Table 12-2.
Table 12-2
ReachableFrom After One Pass through Recursion
Source
Destination
Portland
Orange County
Portland
Charlotte
Portland
Daytona Beach
Orange County
Montgomery
Charlotte
Memphis
Memphis
Champaign
Montgomery
Memphis
The second time through the recursion, things start to get interesting. The WHERE clause (WHERE in.Destination = out.Source) means that you’re looking only at rows where the Destination field of the REACHABLEFROM table equals the Source field of the FLIGHT table. For those rows, you’re taking the Source field from REACHABLEFROM and the Destination field from FLIGHT, and adding those two fields to REACHABLEFROM as a new row. Table 12-3 shows the result of this iteration of the recursion.
Table 12-3
REACHABLEFROM After Two Passes through the Recursion
Source
Destination
Portland
Orange County
Portland
Charlotte