Re: How to: SQL Query with multiple FK relations to single table

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: 26 Sep 2002 01:17:13 -0700
Message-ID: <a20d28ee.0209260017.33d99c42_at_posting.google.com>


carl.stottlemyer_at_lmco.com (Carl) wrote in message news:<bc814416.0209250544.5ffe57d3_at_posting.google.com>...
> The following example seems like it should be simple but it is
> stumping me. How would you construct a SQL query that prints out the
> name (referenced in the People table) of the father and son identified
> in the fathers table.
>
> Table People
> ------------
> pplNo
> pplName
>
> Table Fathers
> -------------
> fatherNo (references People.pplNo)
> sonNo (references People.pplNo)
>
> Thanks,
> Carl

By joining the people table 2 times with fathers

select f.pplname, s.pplname
from fathers, people f, people s
where s.peopleno = fathers.sonno
and f.peopleno = fathers.fatherno

This is a question of the 'homework' type though.

Hth

Sybrand Bakker
Senior Oracle DBA Received on Thu Sep 26 2002 - 10:17:13 CEST

Original text of this message