Re: Double Dipping
| From: | John Hawkins | Date: | Thu, 21 Feb 2002 16:26:10 +0000 |
| Subject: | Re: Double Dipping | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-17139@lists.php.net to get a copy of this message | ||
Ah Ha! I got it. This was a clear case of RTFM...
Based on what you said, I went back and re-read page
67 of "MySQL" by Paul DuBouis and sure enough, it made
sense this time...
Here is what I came up with:
SELECT gamedate, gametime, divisions.name as division,
t1.name as teama, t2.name as teamb FROM divisions,
teams as t1, teams as t2, games WHERE games.leagueID =
'$leagueID' AND t1.ID = hometeamID AND t2.ID =
awayteamID group by gamedate, gametime
Thanks again for all your help!!
John
--- DL Neil <PHPml@DandE.HomeChoice.co.uk> wrote:
> Howdy John,
>
> > Sorry for the lack of information in the subject
> line,
> > but I didn't know how else to explain it
> briefly...
>
> =don't be sorry, re-word it!
>
> > I have 2 tables and they look like this:
> >
> > There are 2 other tables involved, but they don't
> come
> > into play for this portion of the problem so I
> won't
> > bother you with the details.
> >
> > Some sample data may look like this:
> >
> > Table: teams
> > | ID | leagueID | divisionID | name |
> > | 11 | 1 | 5 | Dodgers |
> > | 12 | 1 | 5 | Cobras |
> > | 13 | 1 | 5 | Bombers |
> >
> > Table: games
> > | ID | leagueID | divisionID | hometeamID |
> awayteamID
> > | gamedate | gametime |
> > | 1 | 1 | 1 | 12 | 13
> > | 2002-02-21 | 15:30:00 |
> > | 2 | 1 | 1 | 11 | 12
> > | 2002-02-26 | 15:30:00 |
> >
> > Here's the issue...
> >
> > I want to be able to have it pull in the name for
> each
> > of the teams (home and away) from the database. My
> > existing query looks like the following:
> > (note: $leagueID = 1 in the following line)
> >
> > SELECT gdate, gtime, divisions.name as division,
> > teams.name as teama, teams.name as teamb FROM
> > divisions, teams, games WHERE games.leagueID =
> > '$leagueID' group by gamedate, gametime
> >
> > This has gotten me close, but, not over the hump.
> >
> > As always, I hope I have explained this well
> enough!
>
>
> The missing item that might have been helpful is a
> sample output of what you have so far. I'll guess
> that it's
> something like:
>
> gdate, gtime, division, teama, teamb
> -02-21 15:30 1 blank blank
>
> If you substitute/add hometeamID and awayteamID in
> the resultset (purely for debugging purposes) then
> you should
> see the IDs 12 and 13 appearing, but still no team
> names under teama or teamb.
>
> You probably know that you are missing the join
> between games and teams. There is no reason why you
> cannot have
> two joins - "double dipping". Did you try it?
>
> WHERE...teams.ID=hometeamID AND teams.ID=awayteamID
>
> NB the above does not imply (as some might at first
> think) that hometeamID would have to equal
> awayteamID for
> this to work, the two ANDs/the two joins are
> independently arranged.
>
> Let us know how you get on!
> =dn
>
>
__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com