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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:11:55+00:00 2026-05-28T05:11:55+00:00

I have three tables. First table is Activities and second is Members and last

  • 0

I have three tables.
First table is Activities and second is Members and last is Message.
Activities has a foreign key named Members_ID and primary key is Activity_ID.
Members’ primary key is Members_ID.
Message recorded Activity_ID and Members_ID.
I wanna search about Activities NATURAL JOIN Members and I need a new column count for
Message’s message_ID where the Activity_ID is the same.

NATURAL JOIN:

SELECT*
    FROM Activities 
        NATURAL JOIN Members 
    WHERE Activities.Members_ID = Members.Members_ID;

COUNT(message_ID):

SELECT COUNT(message_ID) 
    FROM Message 
    WHERE Activity_ID = 123;

Question is:
How to search the above two things together?
I’d like have a table have Activities NATURAL JOIN Members with same Activities.Members_ID
and a virtual column which is COUNT(message_ID) from table Message.

  • 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-28T05:11:56+00:00Added an answer on May 28, 2026 at 5:11 am

    Perhaps you wish to use a correlated subquery, like this:

    SELECT *, (SELECT COUNT(message_ID) FROM Message WHERE Activity_ID = a.Activity_ID AND Members_ID = m.Members_ID) AS Message_Count
        FROM Activities AS a
            NATURAL JOIN Members AS m
        WHERE a.Members_ID = m.Members_ID;
    

    But, I would avoid the natural join syntax:

    SELECT *, (SELECT COUNT(message_ID) FROM Message WHERE Activity_ID = a.Activity_ID AND Members_ID = m.Members_ID) AS Message_Count
        FROM Activities AS a
            JOIN Members AS m on a.Members_ID = m.Members_ID;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables in my database. First table is Employee : Second table
Here's some background info. I have three MySQL tables (all InnoDB). The first table
I have an entity context that includes three tables. The first is a table
I have a databse with three tables. The first table is something like: _id
I have three tables. Directors: Directors ID First Name Last Name Films: Films Film
I have three tables that I need get information from, 1 table has the
I have to insert three tables independently .. but if first table is inserted
I have three tables in the many-to-many format. I.e, table A, B, and AB
I have three tables A: A.pID primary key, A.Name nvarchar(250) B: B.pID primary key,
I have a relational database with three tables. The first containts id's that relate

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.