I have four tables in an online sports statistical programs as similar to as follows
Table: Divisions
ID NAME
-- ----------
1 DIVISION A
2 DIVISION B
Table: Teams
ID NAME DIVISION_ID
-- ------- -----------
1 Team 1 1
2 Team 2 2
Table: Players
ID FIRST_NAME LAST_NAME TEAM_ID
-- ---------- --------- -------
1 JOHN DOE 1
2 JIM BOB 2
Table: Player_Stats
ID PLAYER_ID STAT1 STAT2
-- --------- ----- -----
1 1 5 3
2 2 6 2
I need to query the player_stats table by division. I made this post awhile ago and was given this sql. Never got around to it but after trying to implement it, this code below does not work. 'Syntax error in from'
What would be the correct way to query the player_stats table by division_id?
Table: Divisions
ID NAME
-- ----------
1 DIVISION A
2 DIVISION B
Table: Teams
ID NAME DIVISION_ID
-- ------- -----------
1 Team 1 1
2 Team 2 2
Table: Players
ID FIRST_NAME LAST_NAME TEAM_ID
-- ---------- --------- -------
1 JOHN DOE 1
2 JIM BOB 2
Table: Player_Stats
ID PLAYER_ID STAT1 STAT2
-- --------- ----- -----
1 1 5 3
2 2 6 2
I need to query the player_stats table by division. I made this post awhile ago and was given this sql. Never got around to it but after trying to implement it, this code below does not work. 'Syntax error in from'
Code:
SELECT Player_Stats.*
FROM Player_Stats
JOIN Players ON Players.ID = Player_Stats.PlayerID
JOIN Teams ON Teams.ID = Players.Team_ID
WHERE Teams.Division_ID = 2
What would be the correct way to query the player_stats table by division_id?