Skip site navigation (1) Skip section navigation (2)

What am I doing wrong?

From: John Poltorak <jp(at)eyup(dot)org>
To: pgsql-novice(at)postgresql(dot)org
Subject: What am I doing wrong?
Date: 2001-01-16 12:10:29
Message-ID: 20010116121028.A85@eyup.org (view raw or flat)
Thread:
Lists: pgsql-novice
I think I'm doing something fundamenatally wrong when attempting
to use multiple tables. Can someone point out what I'm missing
from the following snippet:-

------------------------------------------
CREATE TABLE players
 (player_id  INTEGER NOT NULL Primary key,
     player  VARCHAR,
    club_id  INTEGER);

CREATE TABLE clubs
 (  club_id  INTEGER NOT NULL Primary key,
       club  VARCHAR ,
foreign key  (club_id) references players);


insert into players values (1, 'Rivaldo');
insert into players values (2, 'Kleivert');
insert into players values (3, 'Zidane');
insert into players values (4, 'Davids');


insert into clubs values (1, 'Barca');
insert into clubs values (2, 'Juve');


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)



It's probably obvious to everyone, but I don't see what I've done
wrong. Any enlightenment would be much appreiated.

--
John



Responses

pgsql-novice by date

Next:From: TamsinDate: 2001-01-16 12:19:32
Subject: RE: What am I doing wrong?
Previous:From: Peter RodriguezDate: 2001-01-16 06:01:46
Subject: Table recognition

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group