php - mysql merge two queries, get count of each value from two seperate columns? -
$accepteventcount = mysql_query("select count(*) count, tbldevices.name, tblevents.sentdeviceid tbldevices,tblevents tbldevices.deviceid = tblevents.sentdeviceid group tblevents.sentdeviceid order count desc"); $declineeventcount = mysql_query("select count(*) cnt, tbldevices.name, tbldeclinedevents.deviceid tbldevices,tbldeclinedevents tbldevices.deviceid = tbldeclinedevents.deviceid group tbldeclinedevents.deviceid order cnt desc");
i'm new merging 2 queries in php mysql. tried unions i'm not able desired result.
basically want count of accepted events , declined events of devices table tbldevices. 3 tables involved here. can me this?
this tried!
select count() count, tbldevices.deviceid,null,tblevents.sentdeviceid tblevents,tbldevices tblevents.sentdeviceid = tbldevices.deviceid group tblevents.sentdeviceid union select count() cnt,tbldevices.deviceid,tbldeclinedevents.deviceid,null tbldevices,tbldeclinedevents tbldeclinedevents.deviceid = tbldevices.deviceid group tbldeclinedevents.deviceid
i think not possible (at least without using sub query). reason group needs done on fields, accepted , declined events not identified field tables.
if can't modified table structure, having 2 queries reasonable options. if can change table structure, recommend adding column store validation status.
Comments
Post a Comment