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

  • SEARCH
  • Home
  • 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 7999799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:36:22+00:00 2026-06-04T15:36:22+00:00

how can I find the total records in this case: I have a table

  • 0

how can I find the total records in this case:

I have a table ‘users’, a table ‘messages’ and a table ‘groups’. A user can sent a message, and that will be stored in the table ‘messages’. Each user can be a member of one group. Now I would like to show the total messages sent by all users in the group on the group-details-page. How can I get all the users in the group and count their messages? What is the best and fastest way to do that?

I can’t work with Joins, so this doesn’t work. I don’t know how to fix it.

SELECT COUNT(Message_id) AS total_messages, d.Userid FROM messages AS
d LEFT JOIN users AS s ON (s.Groupid=$groupid) WHERE
s.Groupid=$groupid

Thanks!

If you need table structure:

** users **
Userid
Groupid

** groups **
Groupid
Some_details

** messages **
Messageid
Userid
Subject
Content
  • 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-06-04T15:36:23+00:00Added an answer on June 4, 2026 at 3:36 pm

    If you’re looking for total messages without needing to know per user, try

    SELECT COUNT(messages.Messageid) as total_messages
    FROM messages
        INNER JOIN users ON messages.Userid = users.Userid
    WHERE users.Groupid = $groupid
    

    Make sure you’re indexing the messages.Userid field as well if you’ll be doing a lot of querying based on it.

    Needing a count per user try

    SELECT 
        COUNT(messages.Messageid) as num_messages,
        messages.Userid
    FROM messages
        INNER JOIN users ON messages.Userid = users.Userid
    WHERE users.Groupid = $groupid
    GROUP BY users.Userid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to find the total number of distinct records in a table. I
How can I find total disk space occupied by a certain user, say located
I can find ample evidence that MongoDBs are always kept in the order given
I'm writing a report that shows total downtime for our website. When a user
I have 2 tables: User and Picture. The Picture table has the key of
There is probably a reeeeeally obvious answer to this, but I can't find it,
I have a table for absentees, and that table am storing the studentids of
Where can find resources about best practices for SharePoint programming? I am talking about
I can find no non-deprecated way of hiding an item in a menu bar
I can find the definition files at http://www.php.net/~helly/php/ext/spl/... but I want to extend DirectoryIterator

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.