Hi all,
I have a situation where I need to get the count of reords in one table which have no corresponding records in another table. The only way I've made it work so far is by using a HAVING clause, which seems to preclude the possibility of using COUNT(*)... or at least when I try to COUNT this query, I get a zero count.
The query above returns two records (below), but I need a query which will return a COUNT(*) type result without having to return the entire record set.
Any ideas?
Thanks in advance,
Chuck
I have a situation where I need to get the count of reords in one table which have no corresponding records in another table. The only way I've made it work so far is by using a HAVING clause, which seems to preclude the possibility of using COUNT(*)... or at least when I try to COUNT this query, I get a zero count.
Code:
SELECT
count(*),
count(service_timesheet.start_time) as checkin
FROM
(services serv,
customers cust,
job_sites work)
LEFT JOIN
service_timesheet on (serv.service_id = service_timesheet.service_id )
WHERE
serv.customer_id = cust.customer_id
and
serv.job_site_id = work.job_site_id
and
serv.disp_date >= '2008-08-01'
and
serv.order_status >= 'Open'
and
NOW() > concat(disp_date, ' 23:39:00')
GROUP BY
serv.service_id
HAVING
checkin = 0
The query above returns two records (below), but I need a query which will return a COUNT(*) type result without having to return the entire record set.
Code:
+----------+---------+
| count(*) | checkin |
+----------+---------+
| 1 | 0 |
| 1 | 0 |
+----------+---------+
2 rows in set (0.01 sec)
Any ideas?
Thanks in advance,
Chuck