Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How To Do 3-Way Join??
"Dianne Siebold" <dsiebold_at_wrightstrat.com> wrote:
>I'm using Oracle 7.3.3 and need to join 3 tables and pull data out of each
>of them. The DRIVER and TRAILER tables could have multiple records for one
>route.
>
>ROUT: ROUT_NBR, ROUT_DESC
>DRIVER: ROUT_NBR, DRIVER_NBR
>TRAILER: ROUT_NBR, TRAILER_NBR
>
>I'm looking for a result like this where a route could have two different
>drivers or two different trailers.
>
>ROUT_NBR ROUT_DESC DRIVER_NBR TRAILER_NBR
>1 Route 1 2
> 4
>1 Route 1 2
> 5
>2 Route 2 3
> 7
>2 Route 2 4
> 7
>
>Any assistance you can provide on SQL Syntax would be helpful. I have
>checked a number of manuals, but they have had little in the way of example
>code.
>
Try:
select r. rout_nbr,r.rout_desc,d.driver_nbr,t.trailer_nbr
from
route r,driver d,trailer t
where
r.rout_nbr = d.rout_nbr and d.rout_nbr = t.rout_nbr
order by r.rout_nbr,d.driver_nbr,t.trailer_nbr;
Its been a while since I wrote sql to do this type of report since I have been spoiled by my report writer ( Crystal Reports v6 ) which makes the process much easier, so please read other replies you may get for better approaches.,
John Greco
Oracle DBA
Received on Thu Oct 23 1997 - 00:00:00 CDT