Reputation: 59
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
Reputation: 204854
select post_id, Count(id) as total
from comments
group by post_id
order by total desc
limit 1
Upvotes: 1