I have the following query
SELECT
c.cd,
c.c_id
FROM
f f
INNER JOIN s s
ON s.s_id = f.s_id
INNER JOIN c c
ON c.c_id = s.c_id
WHERE f.m_id = 2
AND f.deleted = 'no'
GROUP BY s.c_id
ORDER BY f.update_datetime DESC ;
Which returns a sample result set:
c.cd c.c_id
moot 4
derp 5
I have another query based on the c.c_id of the above result set which iterates for each record in the above result set:
SELECT COUNT(*) as totals FROM s
WHERE c_id =?
AND status='good';
returns 7 when c_id=4 and returns 20 when c_id=5
Is there any way I can combine the two queries to form a result set like this?
c.cd c.c_id totals
moot 4 7
derp 5 20
Try this: