select c.kupon, count(*) as count
from kuponbahis c
join bahis b
on b.sonuc = c.secim
and b.ID = c.bahis
group by c.kupon
having count(case when c.bahis ='$sonuclandirilacakbahis' then 1 end) > 0
With this query I'm getting kupon IDs and counts. Then fetching them in PHP and matching with the result of
SELECT COUNT(*) FROM kuponbahis WHERE kupon='$kuponid'
(while fetching the second query, too.) If it's a match, i'm doing some work.
But now, I want to do this in SQL directly.
My PHP code is below;
$kazananKuponlariGetirSorgu = mysql_query("select c.kupon, count(*) as count
from kuponbahis c
join bahis b
on b.sonuc = c.secim
and b.ID = c.bahis
group by c.kupon
having count(case when c.bahis ='$sonuclandirilacakbahis' then 1 end) > 0");
while ($kazananKuponlariGetirSorgux = mysql_fetch_array($kazananKuponlariGetirSorgu)){
$kuponid = $kazananKuponlariGetirSorgux[0];
$tutanbahisadet = $kazananKuponlariGetirSorgux[1];
$kupondakiBahisAdeti = mysql_query("SELECT COUNT(*) FROM kuponbahis WHERE kupon='$kuponid'");
$kupondakiBahisAdetix = mysql_fetch_array($kupondakiBahisAdeti);
if ($kupondakiBahisAdetix[0]==$tutanbahisadet){
//it's a match
}
I tried many queries but they all failed. How can I merge this two sql process to only one?
