slim_jimmy7 Posted March 17, 2012 Share Posted March 17, 2012 MySQL Version: 5.1.61-log $homeallgamestats= mysql_query("SELECT `playerid`,`position`,`playerfirstname`,`playersecondname`,SUM(gamesplayed),SUM(interceptions),SUM(tackles),SUM(sacks),SUM(intyards),SUM(ffumbles),SUM(deftd),SUM(interceptions) + SUM(ffumbles) FROM `seasondbstats`,`seasonfsevenstats` WHERE `season` = $siteyear AND `tackles` > 0 GROUP BY `playerid` ORDER BY SUM(tackles) DESC UNION SELECT `playerid`,`position`,`playerfirstname`,`playersecondname`,SUM(gamesplayed),SUM(interceptions),SUM(tackles),SUM(sacks),SUM(intyards),SUM(ffumbles),SUM(deftd),SUM(interceptions) + SUM(ffumbles) FROM `seasonfsevenstats` WHERE `season` = $siteyear AND `tackles` > 0 GROUP BY `playerid` ORDER BY SUM(tackles) DESC"); Error I am Recieving: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/#####/public_html/####/stats.php on line #### What I have is two tables with the same columns on them. The seasondbstats has extra tables in it so they have to be separated. I want to take the similar data and run them in the same query and compare the stats. So far all I am getting is this error. Formatting or syntax is what my guess is, but I can't get the right combo. Both the SELECT's work separately. Thank you in advance for helping me and my newbish question Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 17, 2012 Share Posted March 17, 2012 Echo the query string and mysql_error(). Quote Link to comment Share on other sites More sharing options...
slim_jimmy7 Posted March 17, 2012 Author Share Posted March 17, 2012 Oops sorry I thought I put that in there, the error is Incorrect usage of UNION and ORDER BY which I knew, I guess what I am asking is how can I get the correct usage of union, or do I have to use join, my head is so turned around Quote Link to comment Share on other sites More sharing options...
slim_jimmy7 Posted March 17, 2012 Author Share Posted March 17, 2012 OK, after thinking clearly and starting from scratch I was able to find out that ORDER BY was in the first one 2x, and that I was pulling from two tables in the first query before the join, after that I was able to find out that I needed to clean up a few more items and now it works! Thank you very much $homeallgamestats= mysql_query("SELECT `playerid`,`position`,`playerfirstname`,`playersecondname`,`tackles`,SUM(gamesplayed),SUM(interceptions),SUM(tackles),SUM(sacks),SUM(intyards),SUM(ffumbles),SUM(deftd),SUM(interceptions) + SUM(ffumbles) FROM `seasondbstats` WHERE `season` = $siteyear AND `tackles` > 0 GROUP BY `playerid` UNION SELECT `playerid`,`position`,`playerfirstname`,`playersecondname`,`tackles`,SUM(gamesplayed),SUM(interceptions),SUM(tackles),SUM(sacks),SUM(intyards),SUM(ffumbles),SUM(deftd),SUM(interceptions) + SUM(ffumbles) FROM `seasonfsevenstats` WHERE `season` = $siteyear AND `tackles` > 0 GROUP BY `playerid` ORDER BY `tackles` 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.