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.
Perhaps you wish to use a correlated subquery, like this:
But, I would avoid the natural join syntax: