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 398249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:43:47+00:00 2026-05-12T16:43:47+00:00

I have 3 tables, each table will show records of users posting messages. I

  • 0

I have 3 tables, each table will show records of users posting messages.

I have managed to sum the number of times each user has posted a message on each table and now I want to sum these 3 individual values together for each user.

Here is what I have managed so far:

Table USERMESSAGE:
SELECT U.SenderID, COUNT(U.SenderID) AS U_NUM
FROM USERMESSAGE AS U
WHERE U.SenderID != U.ReceiverID
GROUP BY U.SenderID

Table COMMENT:
SELECT C.UserID, COUNT(C.UserID) AS C_NUM
FROM COMMENT AS C
GROUP BY C.UserID

Table FRIENDLIST:
SELECT F.UserID, COUNT(F.UserID) AS F_NUM
FROM FRIENDLIST AS F
WHERE F.ListName = 'News Feed'
GROUP BY F.UserID

But not all user will post in all tables, so some UserID will not appear in some tables.

  • 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-12T16:43:48+00:00Added an answer on May 12, 2026 at 4:43 pm

    I would try something like this

    DECLARE @Table1 TABLE(
            UserID INT
    )
    
    DECLARE @Table2 TABLE(
            UserID INT
    )
    
    DECLARE @Table3 TABLE(
            UserID INT
    )
    
    INSERT INTO @Table1 (UserID) SELECT 1
    INSERT INTO @Table1 (UserID) SELECT 2
    INSERT INTO @Table1 (UserID) SELECT 3
    
    INSERT INTO @Table2 (UserID) SELECT 2
    INSERT INTO @Table2 (UserID) SELECT 3
    
    INSERT INTO @Table3 (UserID) SELECT 3
    
    SELECT  ISNULL(CountTable1.CountUserIDTable1,0) +
            ISNULL(CountTable2.CountUserIDTable2,0) +
            ISNULL(CountTable3.CountUserIDTable3,0) CountOverTables,
            UserIDs.UserID
    FROM    (
                SELECT  DISTINCT
                        UserID
                FROM    @Table1
                UNION   
                SELECT  DISTINCT
                        UserID
                FROM    @Table2
                UNION   
                SELECT  DISTINCT
                        UserID
                FROM    @Table3
            ) UserIDs LEFT JOIN
            (
                SELECT  UserID,
                        COUNT(UserID) CountUserIDTable1
                FROM    @Table1
                GROUP BY UserID
            ) CountTable1 ON UserIDs.UserID = CountTable1.UserID LEFT JOIN
            (
                SELECT  UserID,
                        COUNT(UserID) CountUserIDTable2
                FROM    @Table2
                GROUP BY UserID
            ) CountTable2 ON UserIDs.UserID = CountTable2.UserID LEFT JOIN
            (
                SELECT  UserID,
                        COUNT(UserID) CountUserIDTable3
                FROM    @Table3
                GROUP BY UserID
            ) CountTable3 ON UserIDs.UserID = CountTable3.UserID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 200 users each user will eventually have a reviewINFO table with certain
I have a table with dated records. I want a query that will show
I have two tables: Folder, Files. Each table has 4 fields: ParentID, ID, Name,
I used JPA and mysql. Each table have entity class.I have four tables. Table1
I have a flow layout. Inside it I have about 900 tables. Each table
I have a table with two child tables. For each record in the parent
I have a simple parent/child tables. Contract is the parent table. Each contract can
In each table have many number of rows with amount. Like this i have
I'm getting pretty frustrated here. I have a table of records. Next to each
I have one show table which have 25 lakh records in it. Columns in

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.