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. Link to comment https://forums.phpfreaks.com/topic/61708-select-statement/ 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 = ????; Link to comment https://forums.phpfreaks.com/topic/61708-select-statement/#findComment-307224 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? Link to comment https://forums.phpfreaks.com/topic/61708-select-statement/#findComment-307250 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=????; Link to comment https://forums.phpfreaks.com/topic/61708-select-statement/#findComment-307258 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 Link to comment https://forums.phpfreaks.com/topic/61708-select-statement/#findComment-307265 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"; Link to comment https://forums.phpfreaks.com/topic/61708-select-statement/#findComment-307270 Share on other sites More sharing options...
Wildbug Posted July 25, 2007 Share Posted July 25, 2007 Looks okay. Does it work? Link to comment https://forums.phpfreaks.com/topic/61708-select-statement/#findComment-307277 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 Link to comment https://forums.phpfreaks.com/topic/61708-select-statement/#findComment-307280 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"; Link to comment https://forums.phpfreaks.com/topic/61708-select-statement/#findComment-307306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.