Jump to content

grouping two queries / join query?


karimali831

Recommended Posts

I am using two seperate queries to calculate a streak, but the queries must be grouped together to find the actual streak?

 

Query 1:

 

SELECT COUNT(matchID) as streak, clan1 FROM webs_cup_matches WHERE ladID='17' AND clan1='2630' AND score1 > score2 AND confirmscore='1' AND einspruch='0' GROUP BY clan1 ORDER BY streak DESC LIMIT 1

Query 2:

SELECT COUNT(matchID) as streak, clan2 FROM webs_cup_matches WHERE ladID='17' AND clan2='2630' AND score1 < score2 AND confirmscore='1' AND einspruch='0' GROUP BY clan2 ORDER BY streak DESC LIMIT 1

 

is it possible someone can join these queries together?

Link to comment
Share on other sites

Is this correct ? I hope :)

 

$query = 

"SELECT COUNT(matchID) as streak, clan1 FROM webs_cup_matches WHERE ladID='$laddID' AND clan1='$teamID' AND score1 > score2 AND confirmscore='1' AND einspruch='0' GROUP BY clan1 DESC LIMIT 1
    UNION
SELECT COUNT(matchID) as streak, clan2 FROM webs_cup_matches WHERE ladID='$laddID' AND clan2='$teamID' AND score1 < score2 AND confirmscore='1' AND einspruch='0' GROUP BY clan2 ORDER BY streak DESC LIMIT 1";


   $streak = mysql_query($query);

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.