$AcceptEventCount = mysql_query("SELECT COUNT(*) as count, tblDevices.name, tblEvents.sentdeviceid FROM tblDevices,tblEvents WHERE tblDevices.deviceid = tblEvents.sentdeviceid
GROUP BY tblEvents.sentdeviceid ORDER BY count DESC");
$DeclineEventCount = mysql_query("SELECT COUNT(*) as cnt, tblDevices.name, tblDeclinedEvents.deviceid FROM tblDevices,tblDeclinedEvents WHERE tblDevices.deviceid = tblDeclinedEvents.deviceid
GROUP BY tblDeclinedEvents.deviceid ORDER BY cnt DESC");
I'm new to merging two queries in php mysql. I tried unions with it but i'm not able to get the desired result.
Basically I want to get a count of the accepted events and the declined events of the devices from the table tbldevices. Three tables are involved here. can anyone help me with this?
this is what i tried!
SELECT COUNT() as count, tblDevices.deviceid,null,tblEvents.sentdeviceid
from tblEvents,tblDevices
WHERE tblEvents.sentdeviceid = tblDevices.deviceid
GROUP BY tblEvents.sentdeviceid
UNION
SELECT COUNT() as cnt,tblDevices.deviceid,tblDeclinedEvents.deviceid,null
from tblDevices,tblDeclinedEvents
WHERE tblDeclinedEvents.deviceid = tblDevices.deviceid
GROUP BY tblDeclinedEvents.deviceid