Jump to content

Union Problem (Newb)


slim_jimmy7

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/259102-union-problem-newb/
Share on other sites

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");

Link to comment
https://forums.phpfreaks.com/topic/259102-union-problem-newb/#findComment-1328405
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.