So, I'm getting data from one table with a simple SELECT statement with SELECT COUNT included.
SELECT *,
(SELECT COUNT(`message_id`)
FROM `user_message`
WHERE `status_to` = 0
) AS `unread`
FROM `user_message`
Here, unread counts for unread messages coming from other users. But that's not quite enough. What I want is to reference SELECT COUNT to a specific column, user_id, within the same table:
SELECT *,
(SELECT COUNT(`message_id`)
FROM `user_message`
WHERE `status_to` = 0 AND `user_message`.`user_id` = `user_message`.`user_id`
) AS `unread`
FROM `user_message`
.. if that makes sense. My second statement disregards this part: AND user_message.user_id = user_message.user_id, and gives me the same result for each user_id.
What am I missing??