From: | "Tamsin" <tg_mail(at)bryncadfan(dot)co(dot)uk> |
---|---|
To: | "John Poltorak" <jp(at)eyup(dot)org>, <pgsql-novice(at)postgresql(dot)org> |
Subject: | RE: What am I doing wrong? |
Date: | 2001-01-16 12:19:32 |
Message-ID: | NEBBKHBOBMJCHDMGKCNJMEGFCIAA.tg_mail@bryncadfan.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
try this
select player,club from players,clubs where players.club_id = clubs.club_id
You need the where clause in the query to join the tables, otherwise you get
a 'cartesian product' where all combinations of rows are displayed. The
foreign key constraint just constrains the data in the tables, so that you
can't enter a club_id into players which isn't in clubs, but doesn't affect
what you can select from the tables.
HTH
Tamsin
>
>
> select player,club from players,clubs;
> ------------------------------------------
>
> This is the output I get:-
>
>
> player | club
> ----------+-------
> Rivaldo | Barca
> Kleivert | Barca
> Zidane | Barca
> Davids | Barca
> Rivaldo | Juve
> Kleivert | Juve
> Zidane | Juve
> Davids | Juve
> (8 rows)
>
> This is the output I would like:-
>
>
> player | club
> ----------+-------
> Rivaldo | Barca
> Kleivert | Barca
> Zidane | Juve
> Davids | Juve
> (4 rows)
>
From | Date | Subject | |
---|---|---|---|
Next Message | Stephen Hardman | 2001-01-16 14:44:36 | help |
Previous Message | John Poltorak | 2001-01-16 12:10:29 | What am I doing wrong? |