Help with query

From: "ExpoShare(dot)com" <exposhare(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Help with query
Date: 2004-08-11 23:49:05
Message-ID: c507d6de04081116495af918be@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I'm new to SQL and I am having a little difficulty trying to construct
a query that will use the first table in the following list:

TABLE coaching_relationships:
coaching_relationship_id
coach_id
athlete_id

TABLE athletes
athlete_id
user_id

TABLE coaches
coach_id
user_id

TABLE users
user_id
user_name

And use sub-queries (or joins???) to return user names for the coaches
and athletes like this:

Coach | Athletes
=================
Bill | Marge
Bill | Anne
Mary | Judith
Simon | Esther
Simon | Raymond
Simon | Phyllis

...etc...

I can't seem to make the leap from this:

select c.user_id, a.user_id from athletes a, coaches c,
coaching_relationships cr where a.athlete_id = cr.athlete_id and
c.coach_id = cr.coach_id;

which gives me:

user_id | user_id
---------+---------
1 | 1
8 | 1
9 | 2
3 | 4
3 | 5
3 | 6
8 | 10
8 | 11
9 | 7

To resolving it to names...can I use a sub-query to do this? Any
chance somebody can show me how?

Thanks,

Ryan

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message mike g 2004-08-12 04:33:35 Re: New installation of 8.0 Beta1 Failed to create
Previous Message Bruce Momjian 2004-08-11 17:33:00 Re: Another 'db session' question...