gple Posted July 25, 2007 Share Posted July 25, 2007 Here are three tables and a column associated with that table table1 (year) table2 (year,name) table3 (name, id) How do I create a select statement to pull out information in table3 according to the year that is entered. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 25, 2007 Share Posted July 25, 2007 SELECT * FROM table2 JOIN table3 ON table2.name=table3.name WHERE table2.year = ????; Quote Link to comment Share on other sites More sharing options...
gple Posted July 25, 2007 Author Share Posted July 25, 2007 Thanks but what if I needed to pull out more info from another table table1 (team, year) table2 (player, team) table3 (player, stat) how do I join all three so I can see the stat from table3 by plugging in the year? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 25, 2007 Share Posted July 25, 2007 So, add another JOIN. SELECT * (replace * with just what you need) FROM table1 JOIN table2 ON table1.team=table2.team JOIN table3 ON table2.player=table3.player WHERE table1.year=????; Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 25, 2007 Share Posted July 25, 2007 select table1.whatever,table1.whatever,table2.whatever,table2.whatever,table3.whatever,ect ect proper way ok Quote Link to comment Share on other sites More sharing options...
gple Posted July 25, 2007 Author Share Posted July 25, 2007 Does this look ok? $query="select *, (pts/gp) as ppg from ostats JOIN teams on ostats.tid=teams.tid JOIN players on players.id=ostats.id where teams.year='$season' and gp>3 and order by ppg desc"; Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 25, 2007 Share Posted July 25, 2007 Looks okay. Does it work? Quote Link to comment Share on other sites More sharing options...
gple Posted July 25, 2007 Author Share Posted July 25, 2007 No I am getting an error message: supplied argument is not a valid MySQL result resource Quote Link to comment Share on other sites More sharing options...
soycharliente Posted July 25, 2007 Share Posted July 25, 2007 Take off the AND before ORDER BY? $query = "SELECT *, (pts/gp) AS ppg FROM ostats JOIN teams ON ostats.tid=teams.tid JOIN players ON players.id=ostats.id WHERE teams.year='$season' AND gp>3 ORDER BY ppg DESC"; 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.