vimal
vimal

Reputation: 59

Mysql - Trying to get post id with max number of comments from comment table

In MySQL database table comments there are more than 2 billion records and from this table I have to fetch post_id which have max number of comments:

select post_id,Count(id) as total from comments group by post_id

But this give me all the existing post ids with their no of comment from the above query. And I just want the post id with the max no of comments

Upvotes: 0

Views: 217

Answers (1)

juergen d
juergen d

Reputation: 204854

select post_id, Count(id) as total 
from comments 
group by post_id
order by total desc
limit 1

Upvotes: 1

Related Questions