Subject | Re: [firebird-support] Solution for a redundant join? |
---|---|
Author | Louis Kleiman (SSTMS, Inc.) |
Post date | 2012-10-24T18:12:58Z |
Try using aliases:
SELECT
SCHEDULE.DATE_TIME,
HOME_TEAM.TEAM as HomeTeamName,
AWAY_TEAM.TEAM as AwayTeamName
FROM
SCHEDULE
LEFT JOIN TEAMS HOME_TEAM ON SCHEDULE.HOME_TEAMID=HOME_TEAM.PRIMARYKEY
LEFT JOIN TEAMS AWAY_TEAM ON SCHEDULE.AWAY_TEAMID=AWAY_TEAM.PRIMARYKEY
SELECT
SCHEDULE.DATE_TIME,
HOME_TEAM.TEAM as HomeTeamName,
AWAY_TEAM.TEAM as AwayTeamName
FROM
SCHEDULE
LEFT JOIN TEAMS HOME_TEAM ON SCHEDULE.HOME_TEAMID=HOME_TEAM.PRIMARYKEY
LEFT JOIN TEAMS AWAY_TEAM ON SCHEDULE.AWAY_TEAMID=AWAY_TEAM.PRIMARYKEY
On Wed, Oct 24, 2012 at 1:42 PM, Jeff <jeff_j_dunlap@...> wrote:
> **
>
>
> 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? Please see tables
> below:
>
> ***SCHEDULE TABLE***
> PRIMARYKEY HOME_TEAMID AWAY_TEAMID DATE_TIME
> 1 1 2 12/01/2012
> 2 2 3 12/21/2012
> 3 3 1 12/25/2012
>
> ***TEAMS TABLE***
> PRIMARYKEY TEAM_NAME
> 1 TeamA
> 2 TeamB
> 3 TeamC
>
> Please advise, thank you!
>
>
>
[Non-text portions of this message have been removed]