SELECT `s`.*, COUNT(c.id) AS comments FROM `posts` `s` LEFT JOIN `comments` `c` ON `c`.`post_id` = `s`.`id`
Problem w tym, że jeżeli post nie ma komentarzy to nie jest zwracany przez zapytanie. Jak rozwiązać ten problem?
SELECT `s`.*, COUNT(c.id) AS comments FROM `posts` `s` LEFT JOIN `comments` `c` ON `c`.`post_id` = `s`.`id`