Query references same column twice

Query references same column twice

am 04.12.2006 08:19:44 von Ben.j.howard

I have looked around and can't find any help for my SQL problem.

I have a Table which lists people
peopledb.
_____________
id | Name
1 | Fred
2 | Bill
3 | Bob

And a second table which references two people from the first

Partnershipsdb
____________
id | Pship1 | Pship2
1 1 2
2 1 3

I would Like to make a query which Lists both names in each
Partnership.

Result should be
Fred | Bill
Fred | Bob

I've tried queries with Select as, and am having trouble with how to go
about referencing the same column in the peopledb twice.

Any help appreciatted.

Vol

Re: Query references same column twice

am 04.12.2006 11:18:26 von zac.carey

Volition wrote:

> I have looked around and can't find any help for my SQL problem.
>
> I have a Table which lists people
> peopledb.
> _____________
> id | Name
> 1 | Fred
> 2 | Bill
> 3 | Bob
>
> And a second table which references two people from the first
>
> Partnershipsdb
> ____________
> id | Pship1 | Pship2
> 1 1 2
> 2 1 3
>
> I would Like to make a query which Lists both names in each
> Partnership.
>
> Result should be
> Fred | Bill
> Fred | Bob
>
> I've tried queries with Select as, and am having trouble with how to go
> about referencing the same column in the peopledb twice.
>
> Any help appreciatted.
>
> Vol

SELECT * FROM tablea AS a
LEFT JOIN tableb AS t1 ON t1.id = a.column2
LEFT JOIN tableb AS t2 ON t2.id = a.column3
ORDER BY a.column1

Re: Query references same column twice

am 04.12.2006 20:40:57 von onedbguru

strawberry wrote:
> Volition wrote:
>
> > I have looked around and can't find any help for my SQL problem.
> >
> > I have a Table which lists people
> > peopledb.
> > _____________
> > id | Name
> > 1 | Fred
> > 2 | Bill
> > 3 | Bob
> >
> > And a second table which references two people from the first
> >
> > Partnershipsdb
> > ____________
> > id | Pship1 | Pship2
> > 1 1 2
> > 2 1 3
> >
> > I would Like to make a query which Lists both names in each
> > Partnership.
> >
> > Result should be
> > Fred | Bill
> > Fred | Bob
> >
> > I've tried queries with Select as, and am having trouble with how to go
> > about referencing the same column in the peopledb twice.
> >
> > Any help appreciatted.
> >
> > Vol
>
> SELECT * FROM tablea AS a
> LEFT JOIN tableb AS t1 ON t1.id = a.column2
> LEFT JOIN tableb AS t2 ON t2.id = a.column3
> ORDER BY a.column1

Strawberry,

I tend to not give out full answers to such simple cases - it looks too
much like someones class/homework. If he can't find the answer using
google - he really should find another line of work.