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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.