Counting records in MySQL

Results 1 to 2 of 2

Thread: Counting records in MySQL

  1. #1
    Join Date
    Dec 1969

    Default Counting records in MySQL

    Hi<BR><BR>I need to count the number of comments for any single article i have in a db<BR>(MySQL)<BR>I think I get the right SQL Query but I don&#039;t know how to get the ID from<BR>the article I need....well let me show to you.<BR><BR>What I have in my Home page is something like this:<BR><BR>. News1 (Comments 5 )<BR>. News2 (Comments 2 )<BR>. News3 (Comments 7 )<BR>....and so on<BR><BR>The SQL I use to cunt the comment is:<BR><BR>SELECT Count(Article)<BR>FROM Comments<BR>WHERE Article= MMColParam<BR><BR>Now what I don&#039;t know is what to write for the MMColParam to get the right<BR>ID from the News Table and use it to filter the Comments Table to count the<BR>comments.<BR><BR>If I put manually the Default Value in the to test the recordest I get the<BR>right number of comments, but what should I do to make it automatic?<BR><BR>Thanks in advance<BR><BR>Matt<BR>

  2. #2 Guest

    Default RE: Counting records in MySQL

    Assuming that you have a table called Articles with a field called ID containing the relevant ArticleID, this should word:<BR><BR>Select Articles.ID, Count(Comments.Article)<BR>FROM Articles<BR> JOIN Comments PM Articles.ID = Comments.Article<BR>GROUP BY Articles.ID<BR><BR>This will give you a recordset with each article&#039;s ID and the associated count of comments. I believe that this works on mySQL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts