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
https://forums.phpfreaks.com/topic/220615-grouping-two-queries-join-query/
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);

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.