karimali831 Posted December 4, 2010 Share Posted December 4, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/220615-grouping-two-queries-join-query/ Share on other sites More sharing options...
sweeb Posted December 4, 2010 Share Posted December 4, 2010 http://dev.mysql.com/doc/refman/5.0/en/union.html Quote Link to comment https://forums.phpfreaks.com/topic/220615-grouping-two-queries-join-query/#findComment-1142846 Share on other sites More sharing options...
karimali831 Posted December 4, 2010 Author Share Posted December 4, 2010 I had an attempt at this but wasn't successful could you do this for me please? Quote Link to comment https://forums.phpfreaks.com/topic/220615-grouping-two-queries-join-query/#findComment-1142860 Share on other sites More sharing options...
karimali831 Posted December 4, 2010 Author Share Posted December 4, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/220615-grouping-two-queries-join-query/#findComment-1142864 Share on other sites More sharing options...
sweeb Posted December 4, 2010 Share Posted December 4, 2010 Looks good to me Quote Link to comment https://forums.phpfreaks.com/topic/220615-grouping-two-queries-join-query/#findComment-1142976 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.