Hello,

This is my first message in the forum.

Code:
SELECT a.saat, b.saat, MAX( Tgiren + Tcikan ) AS Total
FROM (

SELECT saat, SUM( giren ) AS Tgiren
FROM magaza_sayma
WHERE (
kamera_id
IN (

SELECT cam_id AS cami
FROM katgirencikan
WHERE kat_id =  '2'
AND gc =  'g'
AND gc2 =  'g'
)
)
AND hangi_yil =  '2010'
AND hangi_ay =  '8'
AND ayin_kaci =  '17'
GROUP BY saat
)a, (

SELECT saat, SUM( cikan ) AS Tcikan
FROM magaza_sayma
WHERE (
kamera_id
IN (

SELECT cam_id AS cami
FROM katgirencikan
WHERE kat_id =  '2'
AND gc =  'g'
AND gc2 =  'c'
)
)
AND hangi_yil =  '2010'
AND hangi_ay =  '8'
AND ayin_kaci =  '17'
GROUP BY saat
)b
WHERE a.saat = b.saat
GROUP BY a.saat
ORDER BY Total DESC 
LIMIT 0 , 1
The problem is sometimes the second degree inside query does not return anything, and the whole query returns nothing. I want to change it if the subquery returns nothing, Tgiren or Tcikan equals to 0 so Total can be calculated by only one.

It is very urgent.
Thank you.