I have 3 tables (actually alot more, but three for this query):
#
# Table structure for table `game_mastertbl`
#
CREATE TABLE game_mastertbl (
id int(11) NOT NULL auto_increment,
game_id varchar(20) NOT NULL default '',
tourney_id int(11) NOT NULL default '0',
division_id int(11) NOT NULL default '0',
home_team_id int(11) NOT NULL default '0',
home_points int(11) default NULL,
away_team_id int(11) NOT NULL default '0',
away_points int(11) default NULL,
field_id int(11) NOT NULL default '0',
time time NOT NULL default '00:00:00',
PRIMARY KEY (id)
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `points_mastertbl`
#
CREATE TABLE points_mastertbl (
game_id int(11) NOT NULL default '0',
team_id int(11) NOT NULL default '0',
points int(11) default NULL,
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `team_mastertbl`
#
CREATE TABLE team_mastertbl (
id int(11) NOT NULL auto_increment,
tourney_id int(11) NOT NULL default '0',
division_id int(11) NOT NULL default '0',
team_name varchar(255) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM;
#---------------------------------------------------------
I have the following query which gives me the game information I am looking for:
SELECT g.id,
t1.team_name as home,
t2.team_name as away,
g.time,
f.field_name
FROM game_mastertbl AS g,
team_mastertbl as t1,
team_mastertbl as t2,
field_mastertbl as f
WHERE g.division_id = 1
AND g.tourney_id = 1
AND g.home_team_id = t1.id
AND g.away_team_id = t2.id
AND g.field_id = f.id
ORDER BY 'time' ASC
Which produces the following results:
id home away time field_name
1 Team A Team B 10:10:00 Cactus Park #3
2 Team C Team D 10:10:00 Cactus Park #4
and so on....
I would like to revise this query so that it includes the scores from the points_mastertbl and I can't seem to get it to work. The desired results would be something like:
id home away hm_pts aw_pts time field_name
1 Team A Team B 7 2 10:10:00 Cactus Park #3
2 Team C Team D 0 4 10:10:00 Cactus Park #4
and so on...
I tried this following query, but it only gave me 3 records in the result, I've tried everything I can think of with no luck:
SELECT g.id,
t1.team_name as home,
t2.team_name as away,
p1.points as home_pts,
p2.points as away_points,
g.time,
f.field_name
FROM game_mastertbl AS g,
team_mastertbl as t1,
team_mastertbl as t2,
field_mastertbl as f,
points_mastertbl as p1,
points_mastertbl as p2
WHERE g.division_id = 1
AND g.tourney_id = 1
AND g.home_team_id = t1.id
AND g.away_team_id = t2.id
AND g.field_id = f.id
AND g.id = p1.game_id
AND g.id = p2.game_id
AND t1.id = p1.team_id
AND t2.id = p2.team_id
ORDER BY `time` ASC
Any help is appreciated.
#
# Table structure for table `game_mastertbl`
#
CREATE TABLE game_mastertbl (
id int(11) NOT NULL auto_increment,
game_id varchar(20) NOT NULL default '',
tourney_id int(11) NOT NULL default '0',
division_id int(11) NOT NULL default '0',
home_team_id int(11) NOT NULL default '0',
home_points int(11) default NULL,
away_team_id int(11) NOT NULL default '0',
away_points int(11) default NULL,
field_id int(11) NOT NULL default '0',
time time NOT NULL default '00:00:00',
PRIMARY KEY (id)
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `points_mastertbl`
#
CREATE TABLE points_mastertbl (
game_id int(11) NOT NULL default '0',
team_id int(11) NOT NULL default '0',
points int(11) default NULL,
) TYPE=MyISAM;
# --------------------------------------------------------
#
# Table structure for table `team_mastertbl`
#
CREATE TABLE team_mastertbl (
id int(11) NOT NULL auto_increment,
tourney_id int(11) NOT NULL default '0',
division_id int(11) NOT NULL default '0',
team_name varchar(255) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM;
#---------------------------------------------------------
I have the following query which gives me the game information I am looking for:
SELECT g.id,
t1.team_name as home,
t2.team_name as away,
g.time,
f.field_name
FROM game_mastertbl AS g,
team_mastertbl as t1,
team_mastertbl as t2,
field_mastertbl as f
WHERE g.division_id = 1
AND g.tourney_id = 1
AND g.home_team_id = t1.id
AND g.away_team_id = t2.id
AND g.field_id = f.id
ORDER BY 'time' ASC
Which produces the following results:
id home away time field_name
1 Team A Team B 10:10:00 Cactus Park #3
2 Team C Team D 10:10:00 Cactus Park #4
and so on....
I would like to revise this query so that it includes the scores from the points_mastertbl and I can't seem to get it to work. The desired results would be something like:
id home away hm_pts aw_pts time field_name
1 Team A Team B 7 2 10:10:00 Cactus Park #3
2 Team C Team D 0 4 10:10:00 Cactus Park #4
and so on...
I tried this following query, but it only gave me 3 records in the result, I've tried everything I can think of with no luck:
SELECT g.id,
t1.team_name as home,
t2.team_name as away,
p1.points as home_pts,
p2.points as away_points,
g.time,
f.field_name
FROM game_mastertbl AS g,
team_mastertbl as t1,
team_mastertbl as t2,
field_mastertbl as f,
points_mastertbl as p1,
points_mastertbl as p2
WHERE g.division_id = 1
AND g.tourney_id = 1
AND g.home_team_id = t1.id
AND g.away_team_id = t2.id
AND g.field_id = f.id
AND g.id = p1.game_id
AND g.id = p2.game_id
AND t1.id = p1.team_id
AND t2.id = p2.team_id
ORDER BY `time` ASC
Any help is appreciated.