Go Back   AnandTech Forums > Software > Programming

Forums
· Hardware and Technology
· CPUs and Overclocking
· Motherboards
· Video Cards and Graphics
· Memory and Storage
· Power Supplies
· Cases & Cooling
· SFF, Notebooks, Pre-Built/Barebones PCs
· Networking
· Peripherals
· General Hardware
· Highly Technical
· Computer Help
· Home Theater PCs
· Consumer Electronics
· Digital and Video Cameras
· Mobile Devices & Gadgets
· Audio/Video & Home Theater
· Software
· Software for Windows
· All Things Apple
· *nix Software
· Operating Systems
· Programming
· PC Gaming
· Console Gaming
· Distributed Computing
· Security
· Social
· Off Topic
· Politics and News
· Discussion Club
· Love and Relationships
· The Garage
· Health and Fitness
· Home and Garden
· Merchandise and Shopping
· For Sale/Trade
· Hot Deals with Free Stuff/Contests
· Black Friday 2014
· Forum Issues
· Technical Forum Issues
· Personal Forum Issues
· Suggestion Box
· Moderator Resources
· Moderator Discussions
   

Reply
 
Thread Tools
Old 02-22-2013, 11:04 AM   #1
Graze
Senior Member
 
Join Date: Nov 2012
Posts: 277
Default SQL join of 3 tables

I need to join three tables two of which have matching field I am using for that join and the last table has a field that matches that of the first joined table.

I can successfully join the first two table but can't seem to join the third. My query is below. Can anyone offer a suggestion as to why the join isn't working?


Quote:
SELECT Athlete.Ath_no, Athlete.Last_name, Athlete.First_name, Team.Team_abbr FROM Athlete INNER JOIN Team ON Team.Team_no=Athlete.Team_no INNER JOIN Entry ON Athlete.Ath_no=Entry.Ath_no

Tables and revelant fields

Athlete table
Fields: Ath_no, Team_no

Team table
Fields: Team_no

Entry table
Fields: Ath_no
Graze is offline   Reply With Quote
Old 02-22-2013, 11:28 AM   #2
pauldun170
Platinum Member
 
pauldun170's Avatar
 
Join Date: Sep 2011
Posts: 2,131
Default

Whats the relationships between the tables?
Team has many athletes
Athlete has one team
What is "entry" table?
pauldun170 is online now   Reply With Quote
Old 02-22-2013, 11:31 AM   #3
pauldun170
Platinum Member
 
pauldun170's Avatar
 
Join Date: Sep 2011
Posts: 2,131
Default

What information do you want to get out of this query?
pauldun170 is online now   Reply With Quote
Old 02-22-2013, 02:45 PM   #4
Train
Lifer
 
Join Date: Jun 2000
Posts: 13,094
Default

at first glance your query looks ok, are you getting an error message, or just not the reslts you want?

I'm guessing you either don't need the entry table, or need to add some fields from the entry table to your list of columns
__________________
.
Train is online now   Reply With Quote
Old 02-22-2013, 04:42 PM   #5
Graze
Senior Member
 
Join Date: Nov 2012
Posts: 277
Default

Quote:
Originally Posted by pauldun170 View Post
Whats the relationships between the tables?
Team has many athletes
Athlete has one team
What is "entry" table?
I actually need to join four tables but that wasn't working so I tried three and that didnt work either.
For simplicity sake I left out the join with the forth table since the join with three tables yielded basically the same error I figured once I sorted the three table join then the forth would come off without a hitch.

The Entry table would used for the forth join with an Event table

I was getting an ODBC error in PHP. I am reading from an Access file that was produced by another program.

Seems like Access required some weird parenthesis.
Quote:
"SELECT
Athlete.[Ath_no]
,Athlete.[Last_name]
,Athlete.[First_name]
,Team.[Team_abbr]
FROM
((Athlete
INNER JOIN Team
ON Team.[Team_no] = Athlete.[Team_no])
INNER JOIN Entry
ON Entry.[Ath_no] = Athlete.[Ath_no])";
Thanks for taking a look guys.
Graze is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:59 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.