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

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -