Count between two queries

hi
i want substract two queries in php can any one give suggestion

query 1 : select count(h.studentid) as count,h.classid,h.appointmentid,DATE_FORMAT(a.appointmentdate,‘%m-%d-%Y’) as appointmentdate, DATE_FORMAT(a.appointmentdate,‘%Y%m%d’) as passdate from school_healthcheckup h,school_appointment a where h.schoolid = 16 and a.id = h.appointmentid and h.classid = ‘10’ group by h.classid order by a.appointmentdate DESC;

query 2 ; select count(school_healthcheckup.classid)from school_healthcheckup,school_details
where school_details.schoolid = school_healthcheckup.schoolid and school_healthcheckup.classid= 10 ;

it’s going to take quite a bit of work to fix your queries

first of all, in query 1, you cannot GROUP BY classid only, and then have appointment data in the SELECT list without aggregate functions on them

apparently you’re counting students in a class 10’s healthcheckup…

based on a.id = h.appointmentid i’m going to guess that it’s a one-to-many relationship with multiple healthcheckups possible for each appointment ??

also, please explain what you’re counting in query 2 and what is the relationship between those two tables?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.