Subject RE: [firebird-support] Solution for a redundant join?
Author Leyne, Sean
> The following simple query produces the results below:
>
> SELECT SCHEDULE.DATE_TIME, TEAMS.TEAM FROM SCHEDULE LEFT JOIN
> TEAMS ON SCHEDULE.HOME_TEAMID=TEAMS.PRIMARYKEY
>
> ***QUERY RESULTS (Showing 'Home Team' Column)***
> 12/01/2012 TeamA
> 12/21/2012 TeamB
> 12/25/2012 TeamC
>
> How do I include the corresponding 'Away Team' column?

Use tables aliases to include multiple references to a single table.


SELECT
SCHEDULE.DATE_TIME, HomeTeam.TEAM, AwayTeam.Team
FROM SCHEDULE
LEFT JOIN TEAMS HomeTeam ON HomeTeam.PRIMARYKEY = SCHEDULE.HOME_TEAMID
LEFT JOIN TEAMS AwayTeam ON AwayTeam.PRIMARYKEY = SCHEDULE.AWAY_TEAMID


Sean