How to MAX(COUNT(x)) in SQLite How to MAX(COUNT(x)) in SQLite sqlite sqlite

How to MAX(COUNT(x)) in SQLite


Other solution:

select count(*) as Result from blog_postsgroup by blog_idorder by Result desclimit 1

I'm not sure which solution would run faster, if this one or the one with the subquery.


You can use a subquery. Here's how you do it:

  1. get the number of posts for each blog
  2. select the maximum number of posts

Example:

select max(num_posts) as max_postsfrom (  select blog_id, count(*) as num_posts   from blog_posts   group by blog_id) a

(The subquery is in the (...)).

NB: I'm not a SQLite power user and so I don't know if this works, but the SQLite docs indicate that subqueries are supported.