php - How to calculate sum of comments through specific id

119

I have two table one isblog which contains title and description while the second one iscomment which shows all comments related to specificblog_id.

blog_id is a primary key for theblog table while used as foreign key in thecomment table.

861

Answer

Solution:

Suppose your blog id is 1

SELECT comments.blog_id AS blog_id, count(comments.blog_id) AS total_comment from comments where comments.blog_id = 1 group by comments.blog_id
309

Answer

Solution:

You can use join, count and group by

select a.title, b.description, c.count(*) 
from table_one as a
inner join table_two as b on a.id = b.table_one_id
group by a.title, b.description

People are also looking for solutions to the problem: php - TYPO3: Save and edit the first & last name of an FE user

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.