开发者

Count number of comments in articles

Please I want to add开发者_StackOverflow中文版 another table (Comments) to this query to count the number of comments for each article.

$query  = "SELECT M.id,M.j_surname,A.j_user_id,A.id,A.jart_title, A.jart_description, A.jart_createddate, COUNT(C.artid) AS count_comments FROM jt_articles A, jt_members M, jt_article_comments C where M.id = A.j_user_id AND C.artid = A.id ORDER BY A.jart_createddate DESC


update: something like that (you dont post the scheme of the comments table)

      SELECT M.id,M.j_surname,A.j_user_id,A.id,A.jart_title, A.jart_description,
     A.jart_createddate , COUNT(A.id) AS count_comments
        FROM jt_articles A
left join  jt_members M on M.id = A.j_user_id 
left join  jt_article_comments C on C.artid = A.id        
        group by A.id
        ORDER BY A.jart_createddate DESC
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜