Welcome.....
I want to get the most user post on my rails app
@section.posts.select("posts.*, count(posts.user_id) as user_posts_count").group('posts.user_id')
.order("user_posts_count DESC").limit(10)
But I have issue with postgreSQL while my code work without any issue on sqlit3 and mysql2
PG::GroupingError: ERROR: column "posts.id" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: SELECT posts.*, count(posts.user_id) as user_posts_count FR...
I need to use postgreSQL because it is the best for heroku but i don't know why I get this error on PostgreSQL
I hope if anyone help me >>>
select *withgroup by.select()must also be in yourgroup(). Excluding of course calculations likecount(),sum(),avg(), etc. You probably only want to select something like user_id.@section.posts.select("user_id, count(user_id) as user_posts_count").group(:user_id).order("user_posts_count DESC").limit(10).