Help with query - Mailing list pgsql-novice

From ExpoShare.com
Subject Help with query
Date
Msg-id c507d6de04081116495af918be@mail.gmail.com
Whole thread Raw
Responses Re: Help with query
List 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

pgsql-novice by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: Another 'db session' question...
Next
From: mike g
Date:
Subject: Re: New installation of 8.0 Beta1 Failed to create