Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proper Syntax to join through multiple tables?

Status
Not open for further replies.

Hutts

Programmer
Jun 6, 2006
7
0
0
US
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'


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?
 
Player_ID - a typo, still has Syntax error in FROM clause
 
Syntax error in FROM clause
Seems like a JetSQL error ...
What is your RDBMS ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Access DB on JRUN Server (JDBC Driver & ODBC Driver)
 
I guessed right ...
JetSQL syntax:
SELECT Player_Stats.*
FROM [!]([/!]Player_Stats
JOIN Players ON Players.ID = Player_Stats.Player_ID[!])[/!]
JOIN Teams ON Teams.ID = Players.Team_ID
WHERE Teams.Division_ID = 2

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
still comes up with a syntax error this time in 'JOIN'
 
still comes up with a syntax error this time in 'JOIN'
keyword INNER is not optional ;-)


please, next time post in forum701

proprietary SQL (e.g. the stupid parentheses that access requires if there are more than two tables in the query) is not really what the ANSI SQL forum is for

:)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top