Answer the question
In order to leave comments, you need to log in
How to count the most popular element in a table via join table?
There is a comment model and a hashtag model connected by a “many to many” relationship through the join table comments_hashtags with the comment_id and hashtag_id keys.
How to count the most popular hashtag? those who have the most? Whether it is possible to make it more or less regular means of active record'a? Thanks in advance!
Answer the question
In order to leave comments, you need to log in
I also forgot order by. Try with limit
select * from (select hashtag_id, count(*) as cnt from comments_hashtags group by hashtag_id order by cnt) LIMIT 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question