I have dialogs and messages. The goal is to select dialogs and their count of unreaded messages. Table messages has unread field to detect it.
I’ve tried this
SELECT *, count(unread) as nums
FROM dialogs JOIN messages ON dialogs.id=messages.dialog_id
GROUP BY dialogs.id
HAVING count(unread) <> 0
but always get total count of messages
If “unread” is, as you state, a count of unread messages, then it always has a value, even if zero, and is always included in COUNT(unread).
Try inserting a
WHERE messages.unread != 0