I've been racking my brain to no avail trying to get this query to work out...probably something simple but here it is...
I've essentially got the following query
SELECT nbag.,ft.,fl., p., s.*
FROM
fantasy_teams as ft,nba_players AS p,fantasy_lineups AS fl,
nba_games as nbag LEFT JOIN nba_stats AS s
ON ((s.tm = nbag.home_team OR s.tm = nbag.away_team) AND
s.game_date = nbag.game_date)
WHERE
fl.player_id = s.player_id AND
p.player_id = fl.player_id AND
ft.team_id = fl.team_id AND
week = '2003-10-27' AND
nbag.game_date >= '2003-10-27' AND
nbag.game_date < '2003-11-03'
ORDER BY fl.team_id, fl.status desc,p.player_id,nbag.game_date
The key tables having to do with the LEFT JOIN are the games and stats tables. The stats table only has records for games that a player actually played in. The two tables in question have the following format.
nba_games
pkey
game_date
home_team
away_team
nba_stats
pkey
game_date
tm
player_id
multiple stat fields...
So basically I'm trying to set up one query that grabs all the games played in a particular week including game records that are not in the stats table (ie a player may have been injured).
I beleive the problem is stemming from the fact that the tm field in the stats table can be one of two fields in the games table, but I'm not sure.
It's probably just too late right now and I'm missing something simple but for the life of me it's eluding my consciousness.
Can anybody help out here.
Thanks in advance.