I am trying to select all from stuff and count the total amount of items in morestuff where stuff id = morestuff id.
select *,
COUNT(morestuff.items) as total
from stuff,
morestuff
where stuff.id = '{$id}'
and morestuff.id = stuff.id
Obviously there is something wrong with my query, can anyone help?
SELECT s.*, coalesce(ms.Count, 0) as Count
FROM stuff s
left outer join (
select id, count(*) as Count
from morestuff
group by id
) ms on s.id = ms.id
WHERE s.id='{$id}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With