Subject Re: [firebird-support] Re: 2 inner joins on the same table
Author Helen Borrie
At 06:21 PM 9/03/2005 +0000, you wrote:

>--- In firebird-support@yahoogroups.com, "Dan Wilson" <dwilson@d...>
>wrote:
> > On 3/9/2005 at 5:55 PM Ricardo wrote:
> >
> > > I have a table Match in which each match has two teams. The teams
>are
> > > stored on the Team table. When I get one match, I need to get the
> > > names of both teams.
> > >
> >
> > assume table Team has two fields: id and name
> > assume table Match has two fields: team1 and team2, which are
>foreign key references to id in Team
> >
> > select team1, team2, t1.name, t2.name from Match
> > inner join Team t1 on team1 = t1.id
> > inner join Team t2 on team2 = t2.id;
> >
> > Is that what you want to do?
> >
> > HTH,
> >
> > Dan.
>
>Yes, but it doesn't work. I get the error:
>
>Invalid token.
>Dynamic SQL Error.
>SQL error code = -104.
>Token unknown - line 6, char 1.
>INNER.

It doesn't mean INNER is not an allowed keyword (although it is optional,
since JOIN without LEFT, RIGHT or OUTER is an inner join by nature!). It's
not a dialectal issue, either. It means something was missing in the
preceding clause - in this case, the table alias for Match.

Fix it as follows:

select m.team1, m.team2, t1.name, t2.name from Match m
inner join Team t1 on m.team1 = t1.id
inner join Team t2 on m.team2 = t2.id;

./heLen