Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Ora 9.2 SQL: What's the fastest way to do this set operation...

Re: Ora 9.2 SQL: What's the fastest way to do this set operation...

From: Brian Peasland <oracle_dba_at_nospam.peasland.net>
Date: Sun, 30 Apr 2006 16:00:13 GMT
Message-ID: <IyJLsK.LyF@igsrsparc2.er.usgs.gov>


You'll need to know that train T_A goes from point A to point C. So your table will contain TRAIN_NAME (T_A), SOURCE point (A) and DEST point (C). Similarly, you'll need to know that train T_B goes from point C to point B. So your table will contain SOURCE point (C) and DEST point (B). Now a simple SQL statment will find the two trains:

SELECT L1.TRAIN_NAME AS LEG1_TRAIN, L2.TRAIN_NAME AS LEG2_TRAIN FROM TRAIN_SCHEDULES L1, TRAIN_SCHEDULES L2 WHERE L1.DEST = L2.SOURCE
   AND L1.SOURCE = 'A' AND L2.DEST = 'B'; The above will give you any trains that start at point A for leg 1, arrive at point B for leg 2, and share a common midpoint for the overall leg.

The query above does not take into account that the LEG1_TRAIN may arrive after the departure of the LEG2_TRAIN. So you might have to modify the query to take that into account....

Cheers,
Brian

-- 
===================================================================

Brian Peasland
oracle_dba_at_nospam.peasland.net
http://www.peasland.net

Remove the "nospam." from the email address to email me.


"I can give it to you cheap, quick, and good.
Now pick two out of the three" - Unknown
Received on Sun Apr 30 2006 - 11:00:13 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US