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

Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Q: Proper and best way to join 3 tables?

Re: SQL Q: Proper and best way to join 3 tables?

From: Martijn Tonies <m.tonies_at_upscene-removethis.nospam.com>
Date: Tue, 27 Sep 2005 23:16:39 +0200
Message-ID: <11jjdjn344nt9e8@corp.supernews.com>


Hello Rob,

> If table A is the parent table and B and C are children with the PK of A
> being a FK in each of B and C.
>
> I have tried:
> select A.pk,B.fk,C.fk
> from A,B,C
> where A.pk = B.fk
> and A.pk = C.fk;
>
> This does not seem to work.
>
> Basically I have an inventory table, a cost table and a comments table.
>
> The part_no key is the pk of Inventory and is also a foreign key in the
> other two tables. I am trying to make a query that returns all the
> Inventory with the Unit_Cost from the Cost table as well as a
> Manufacturer from the Comments table.
> I can do two tables but not 3.

select a.PK, b.FK, c.FK
from a join b on (a.pk = b.fk)
join c on (a.pk = c.fk)

for optional items, use "left join"

If this "doesn't work", then you might perhaps start with telling us what "doesn't work" means.

-- 
With regards,

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, Oracle & MS SQL
Server
Upscene Productions
http://www.upscene.com
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com
Received on Tue Sep 27 2005 - 16:16:39 CDT

Original text of this message

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