开发者

Count number of articles in categories

开发者 https://www.devze.com 2023-01-26 05:47 出处:网络
This code only shows categories with articles in them. I want to show all categories. Pls help. $query = \"SELECT C.id, C.jcat_name,COUNT(A.catid) AS catid FROM jt_categories C INNER J开发者_Python百

This code only shows categories with articles in them. I want to show all categories. Pls help.

$query = "SELECT C.id, C.jcat_name,COUNT(A.catid) AS catid FROM jt_categories C INNER J开发者_Python百科OIN jt_articles A ON C.id = A.catid GROUP BY C.id";


change to left join

 SELECT C.id, C.jcat_name,COUNT(A.catid) AS catid FROM jt_categories C 
LEFT JOIN jt_articles A ON C.id = A.catid GROUP BY C.id


Change INNER JOIN for LEFT JOIN in your query.

INNER JOIN looks explicitely for the join in the data


replace the inner join by a left outer join


Change INNER JOIN to LEFT JOIN.


Did u try LEFT JOIN ? bc. (i think) in second table u have NULL articles for some categories.

0

精彩评论

暂无评论...
验证码 换一张
取 消