Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7404919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:19:33+00:00 2026-05-29T05:19:33+00:00

I am trying to count the total comments posted by single user. Here is

  • 0

I am trying to count the total comments posted by single user. Here is the table structure of the comments table:

CREATE TABLE `PLD_COMMENT` (
   `ID` int(11) NOT NULL auto_increment,        
   `ITEM_ID` varchar(11) NOT NULL,
   `USER_ID` varchar(11) NOT NULL,
   `USER_NAME` varchar(255) NOT NULL, 
   `COMMENT` longtext,
   `COMMENT_TITLE` varchar(255) default NULL,
   `COMMENT_RATING` tinyint(1) default '1', 
   `TYPE` int(11) NOT NULL, 
   `DATE_ADDED` timestamp NOT NULL 
       default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
   `IPADDRESS` varchar(15) default NULL,
   `STATUS` varchar(11) NOT NULL, 
    PRIMARY KEY  (`ID`)  
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1

Here is the table structure for user table

CREATE TABLE `pld_user`(
    `ID` int(11) NOT NULL auto_increment,
    `LOGIN` varchar(100) NOT NULL,
    `NAME` varchar(255) NOT NULL,
    `PASSWORD` varchar(46) NOT NULL,
    `LEVEL` tinyint(4) NOT NULL default '0',
    `RANK` tinyint(4) NOT NULL default '0',
    `ACTIVE` tinyint(4) NOT NULL default '0',
    `LAST_LOGIN` timestamp NOT NULL 
        default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
    `REGISTRATION_DATE` timestamp NOT NULL default '0000-00-00 00:00:00',
    `AUTH_IMG` varchar(255) default NULL,
    `AUTH_IMGTN` varchar(255) default NULL,
    `SUBMIT_NOTIF` tinyint(4) NOT NULL default '1', 
    `PAYMENT_NOTIF` tinyint(4) NOT NULL default '1', 
    `ADDRESS` varchar(255) default NULL, 
    `EMAIL` varchar(255) NOT NULL,
    `WEBSITE` varchar(255) default NULL, 
    `WEBSITE_NAME` varchar(255) default NULL,
    `INFO` varchar(255) default NULL, 
    `ANONYMOUS` tinyint(4) NOT NULL default '0', 
    `LANGUAGE` varchar(2) default NULL, 
    `AVATAR` varchar(100) default NULL,
    `ICQ` varchar(15) default NULL, 
    `AIM` varchar(255) default NULL, 
    `YIM` varchar(255) default NULL, 
    `MSN` varchar(255) default NULL, 
    `CONFIRM` varchar(10) default NULL,
    `NEW_PASSWORD` varchar(46) default NULL,
    `EMAIL_CONFIRMED` int(11) NOT NULL default '1', 
    `LNAME` varchar(255) default NULL,
    `CITY` varchar(255) default NULL, 
    `STATE` varchar(255) default NULL,
    `DOB` date default NULL,
    `UTYPE` tinyint(1) NOT NULL default '0',
    PRIMARY KEY  (`ID`) 
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1 
 COMMENT='Stores all the users with informations'

Here is my query:

SELECT count(c.USER_ID) as total_commments_user , 
  c.*, u.NAME, l.TITLE as LINK_TITLE, u.AUTH_IMG
FROM `PLD_COMMENT` c
left outer join `PLD_USER` u ON (u.ID = c.USER_ID) 
left outer join `PLD_LINK` l ON (l.ID = c.ITEM_ID AND l.STATUS='2') 
WHERE c.TYPE = '1' 
  AND c.STATUS = '2' 
group by c.ID ORDER BY c.ID DESC LIMIT 0 , 3

When I run this query I got 1 in each row under total_comments_user.

Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:19:33+00:00Added an answer on May 29, 2026 at 5:19 am

    You need to add all the columns you are selecting in the SELECT clause except the c.USER_ID to the GROUP BY clause, like this:

    group by c.ID, c.otherfields, l.title,..
    

    EDIT: I think the following will work properly:

    SELECT count(c.USER_ID) as total_commments_user , 
           c.*, u.NAME, l.TITLE as LINK_TITLE, u.AUTH_IMG
    FROM `PLD_COMMENT` c 
    left outer join `PLD_USER` u ON (u.ID = c.USER_ID) 
    left outer join `PLD_LINK` l ON (l.ID = c.ITEM_ID) 
    group by c.ITEM_ID, c.USER_ID
    ORDER BY c.USER_ID, l.ID 
    

    Example:
    If you have the following sample data:

    • PLD_LINK:

      ID   STATUS   TITLE    
      1      1      title1
      2      2      title2
      
    • PLD_USER:

      ID     NAME
      8    Mahmoud
      9     Ahmed
      
    • PLD_COMMENT:

      ID   ITEM_ID USER_ID   STATUS
      4      1        8        1
      5      1        8        1
      6      1        8        1
      7      2        8        2
      8      2        8        2
      9      1        9        1
      10     1        9        1
      

    Case 1: the user Mahmoud is displayed twice:

    Then, the previous query will give you the count of the comments for each User and for each item too, like this:

    total_commments_user  ID  ITEM_ID   USER_ID   Name
             3            4      1         8     Mahmoud
             2            7      2         8     Mahmoud
             2            9      1         9      Ahmed
    

    Notice that the user Mahmoud is displayed twice with a different count, becouse he has different Item_Id.


    Case 2: the user Mahmoud is diplayed only one time:

    If you want to get the count of comments for each user for all items then you will need to group by only the USER_ID and you will got:

    total_commments_user  ID  ITEM_ID   USER_ID   Name  
             5            4      1         8     Mahmoud
             3            9      1         9      Ahmed
    

    As you can see now the user Mahmoud is displayed only one time, becouse we ingonred Item_Id.

    You can then filter by status or what ever.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select the order total sum ($) and invoice count over a
Trying to count how many elements within the array are not equal to 0,
I'm trying to count the number of records that have a null DateTime value.
I am trying to count characters in comments included in C code using Python
I am trying to count the number of rows whose date has not yet
I am trying to get the total count and total sum per salesperson but
I'm trying to count the total number of rows that would have been returned
I am trying to inlude the total count as a column in the query:
I am trying to get a total record count from the below Method using
I am trying to get the total count of rows from Sqlite DB. Following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.