JohnJSal Posted August 23, 2006 Share Posted August 23, 2006 Hi everyone. I'm fairly comfortable with the basics of MySQL, but I'm a little stumped on how to join three tables. First off, let me explain the table structures (from a baseball database):Master | playerID, nameFirst, nameLastSchools | schoolID, schoolNameSchoolsPlayers | playerID, schoolIDSo the first name in each row is the table name (Master, etc.) and the following names are entries in that table. What I'd like to do is write a query that will display a player's name and the school he went to. This is what I've come up with so far, but I don't know if it works yet because my script isn't working properly (a separate issue).select Master.nameFirst, Master.nameLast, Schools.schoolNamefrom Master, Schools, SchoolsPlayerswhere Master.playerID = SchoolsPlayers.playerID and Schools.schoolID = SchoolsPlayers.schoolIDI did a little searching and came across the use of a left or right join as another way to work with more than two tables, but I've never used that before, so I don't know if it's necessary or how it works. It seems like a join is what I need, which the above is not, and I'd like to learn how to write one that uses three (or more) tables. (I can handle two!)Thanks!JohnQuick note: This does work, but is it better to use joins in a case like this? Quote Link to comment Share on other sites More sharing options...
fenway Posted August 23, 2006 Share Posted August 23, 2006 If you know how to do it with 2, you can do it with N -- but try rewriting it in proper JOIN syntax, and the ON clauses will make life simpler for you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.