Subject | RE: [firebird-support] Solution for a redundant join? |
---|---|
Author | Leyne, Sean |
Post date | 2012-10-24T17:50:08Z |
> The following simple query produces the results below:Use tables aliases to include multiple references to a single table.
>
> 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?
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