Rails 4.0.0, Ruby 2.0 class Title < ... ... has_many :comments def self.order_by_number_of_comments_descending select(''titles.*, count(comments.id) AS comments_count''). joins(:comments). group(''titles.id''). order(''comment_count DESC'') end results in a malformed SQL on Postgres, SELECT COUNT(*) AS count_all, titles.id AS titles_id FROM "titles" INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY titles.id ORDER BY comments_count DESC I''ve contacted @steveklabnik and he''d re-open an issue reporting this bug.<https://github.com/rails/rails/issues/5588>In the meantime, has anybody got around this? The SQL is all correct until you call group. Thanks for helping -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5def0eff-649b-4e00-9b87-154f02b9f34d%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Carlos Figueiredo
2013-Jul-23 12:36 UTC
Re: Using :group with #count generating bad SQL in Postgres
Your query is wrong... You need group all columns you show that arent the result of an aggregate function... So your group would be group(''titles.*'') Em 22/07/2013 18:22, "yaw" <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> escreveu:> Rails 4.0.0, Ruby 2.0 > > class Title < ... > ... > > has_many :comments > > def self.order_by_number_of_comments_descending > select(''titles.*, count(comments.id) AS comments_count''). > joins(:comments). > group(''titles.id''). > order(''comment_count DESC'') > end > > results in a malformed SQL on Postgres, > > > SELECT COUNT(*) AS count_all, titles.id AS titles_id FROM "titles" > INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY > titles.id ORDER BY comments_count DESC > > I''ve contacted @steveklabnik and he''d re-open an issue reporting this bug.<https://github.com/rails/rails/issues/5588>In the meantime, has anybody got around this? The SQL is all correct until > you call group. > Thanks for helping > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/5def0eff-649b-4e00-9b87-154f02b9f34d%40googlegroups.com > . > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXsquwiLear7OOO3ZJ-r-wzoO499L8JAhOVCWLNQGLXyPQ%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Yaw Boakye elGran
2013-Jul-23 16:48 UTC
Re: Using :group with #count generating bad SQL in Postgres
Can you write the right (no pun intended) query here? Thanks On Tue, Jul 23, 2013 at 12:36 PM, Carlos Figueiredo < carlos.figueiredo87-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Your query is wrong... > You need group all columns you show that arent the result of an aggregate > function... > So your group would be group(''titles.*'') > Em 22/07/2013 18:22, "yaw" <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> escreveu: > > Rails 4.0.0, Ruby 2.0 >> >> class Title < ... >> ... >> >> has_many :comments >> >> def self.order_by_number_of_comments_descending >> select(''titles.*, count(comments.id) AS comments_count''). >> joins(:comments). >> group(''titles.id''). >> order(''comment_count DESC'') >> end >> >> results in a malformed SQL on Postgres, >> >> >> SELECT COUNT(*) AS count_all, titles.id AS titles_id FROM "titles" >> INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY >> titles.id ORDER BY comments_count DESC >> >> I''ve contacted @steveklabnik and he''d re-open an issue reporting this >> bug. <https://github.com/rails/rails/issues/5588> In the meantime, has >> anybody got around this? The SQL is all correct until you call group. >> Thanks for helping >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/rubyonrails-talk/5def0eff-649b-4e00-9b87-154f02b9f34d%40googlegroups.com >> . >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXsquwiLear7OOO3ZJ-r-wzoO499L8JAhOVCWLNQGLXyPQ%40mail.gmail.com > . > > For more options, visit https://groups.google.com/groups/opt_out. > > >-- visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or +233273201210 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDvcJkAuDiQHV9sH6%3DiaXdBz%3DAEZzxqrW0odBJi33Oyb%3Dw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Carlos Figueiredo
2013-Jul-23 19:11 UTC
Re: Using :group with #count generating bad SQL in Postgres
def self.order_by_number_of_comments_descending select(''titles.id, titles.name, titles.whatever, count(comments.id) AS comments_count''). joins(:comments). group(''titles.id, titles.name, titles.whatever''). order(''comment_count DESC'') end Assuming titles model is like (id, name, whatever) The result query expected is: SELECT COUNT(*) AS comments_count, titles.id AS titles_id, titles.name as titles_name, titles.whatever as titles_whatever FROM "titles" INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY titles.id, titles.name, titles.whatever <http://titles.id> ORDER BY comments_count DESC Atenciosamente, *Carlos Figueiredo* On Tue, Jul 23, 2013 at 1:48 PM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Can you write the right (no pun intended) query here? Thanks > > > On Tue, Jul 23, 2013 at 12:36 PM, Carlos Figueiredo < > carlos.figueiredo87-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Your query is wrong... >> You need group all columns you show that arent the result of an aggregate >> function... >> So your group would be group(''titles.*'') >> Em 22/07/2013 18:22, "yaw" <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> escreveu: >> >> Rails 4.0.0, Ruby 2.0 >>> >>> class Title < ... >>> ... >>> >>> has_many :comments >>> >>> def self.order_by_number_of_comments_descending >>> select(''titles.*, count(comments.id) AS comments_count''). >>> joins(:comments). >>> group(''titles.id''). >>> order(''comment_count DESC'') >>> end >>> >>> results in a malformed SQL on Postgres, >>> >>> >>> SELECT COUNT(*) AS count_all, titles.id AS titles_id FROM "titles" >>> INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY >>> titles.id ORDER BY comments_count DESC >>> >>> I''ve contacted @steveklabnik and he''d re-open an issue reporting this >>> bug. <https://github.com/rails/rails/issues/5588> In the meantime, has >>> anybody got around this? The SQL is all correct until you call group. >>> Thanks for helping >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/rubyonrails-talk/5def0eff-649b-4e00-9b87-154f02b9f34d%40googlegroups.com >>> . >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXsquwiLear7OOO3ZJ-r-wzoO499L8JAhOVCWLNQGLXyPQ%40mail.gmail.com >> . >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > > -- > visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or > +233273201210 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDvcJkAuDiQHV9sH6%3DiaXdBz%3DAEZzxqrW0odBJi33Oyb%3Dw%40mail.gmail.com > . > > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXvddWyJsBgHqV4BMkacGV1Jo2kBa1iO%2BS594FEBfNiNzA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Carlos Figueiredo
2013-Jul-23 19:18 UTC
Re: Using :group with #count generating bad SQL in Postgres
Sorry... Are there more columns on titles entity? If yes... the problem is that you tried to show columns you weren''t grouping... and on postgresql it blows an exception... but if there is only one column on titles... (titles.id) so, I can''t figure out what''s the problem you mentioned... What were your expected SQL to say that the result were malformed? Atenciosamente, *Carlos Figueiredo* On Tue, Jul 23, 2013 at 4:11 PM, Carlos Figueiredo < carlos.figueiredo87-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > def self.order_by_number_of_comments_descending > select(''titles.id, titles.name, titles.whatever, count(comments.id) > AS comments_count''). > joins(:comments). > group(''titles.id, titles.name, titles.whatever''). > > order(''comment_count DESC'') > end > > Assuming titles model is like (id, name, whatever) > > The result query expected is: > SELECT COUNT(*) AS comments_count, titles.id AS titles_id, titles.name as > titles_name, titles.whatever as titles_whatever FROM "titles" > INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY titles.id, > titles.name, titles.whatever <http://titles.id> ORDER BY comments_count > DESC > > Atenciosamente, > > *Carlos Figueiredo* > > > On Tue, Jul 23, 2013 at 1:48 PM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> Can you write the right (no pun intended) query here? Thanks >> >> >> On Tue, Jul 23, 2013 at 12:36 PM, Carlos Figueiredo < >> carlos.figueiredo87-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> Your query is wrong... >>> You need group all columns you show that arent the result of an >>> aggregate function... >>> So your group would be group(''titles.*'') >>> Em 22/07/2013 18:22, "yaw" <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> escreveu: >>> >>> Rails 4.0.0, Ruby 2.0 >>>> >>>> class Title < ... >>>> ... >>>> >>>> has_many :comments >>>> >>>> def self.order_by_number_of_comments_descending >>>> select(''titles.*, count(comments.id) AS comments_count''). >>>> joins(:comments). >>>> group(''titles.id''). >>>> order(''comment_count DESC'') >>>> end >>>> >>>> results in a malformed SQL on Postgres, >>>> >>>> >>>> SELECT COUNT(*) AS count_all, titles.id AS titles_id FROM "titles" >>>> INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY >>>> titles.id ORDER BY comments_count DESC >>>> >>>> I''ve contacted @steveklabnik and he''d re-open an issue reporting this >>>> bug. <https://github.com/rails/rails/issues/5588> In the meantime, has >>>> anybody got around this? The SQL is all correct until you call group. >>>> Thanks for helping >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ruby on Rails: Talk" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/rubyonrails-talk/5def0eff-649b-4e00-9b87-154f02b9f34d%40googlegroups.com >>>> . >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXsquwiLear7OOO3ZJ-r-wzoO499L8JAhOVCWLNQGLXyPQ%40mail.gmail.com >>> . >>> >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> >> >> -- >> visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or >> +233273201210 >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDvcJkAuDiQHV9sH6%3DiaXdBz%3DAEZzxqrW0odBJi33Oyb%3Dw%40mail.gmail.com >> . >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXu-qYKESOxwvgTjM4%2BVxgfFr06x7hEFMHG5t9P8ub_n1A%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Yaw Boakye elGran
2013-Jul-24 00:28 UTC
Re: Using :group with #count generating bad SQL in Postgres
There are at least 2 problems with how you recommend the query to be written: 1. Why would titles.* work in regular SQL but not in Rails'' selectmethod? What would be the case if I have 100 columns on the titles table? 2. During grouping, the normal SQL requirement is to group on a column that is on both tables. As far as I know, grouping can''t be done on two tables when they don''t a common column. In your group call, only titles.id would be useful. The rest won''t Did you try running the resulting query? It should throw an exception concerning the GROUP BY On Tue, Jul 23, 2013 at 7:18 PM, Carlos Figueiredo < carlos.figueiredo87-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sorry... > Are there more columns on titles entity? If yes... the problem is that you > tried to show columns you weren''t grouping... and on postgresql it blows an > exception... but if there is only one column on titles... (titles.id) so, > I can''t figure out what''s the problem you mentioned... > > What were your expected SQL to say that the result were malformed? > > Atenciosamente, > > *Carlos Figueiredo* > > > On Tue, Jul 23, 2013 at 4:11 PM, Carlos Figueiredo < > carlos.figueiredo87-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> >> def self.order_by_number_of_comments_descending >> select(''titles.id, titles.name, titles.whatever, count(comments.id) >> AS comments_count''). >> joins(:comments). >> group(''titles.id, titles.name, titles.whatever''). >> >> order(''comment_count DESC'') >> end >> >> Assuming titles model is like (id, name, whatever) >> >> The result query expected is: >> SELECT COUNT(*) AS comments_count, titles.id AS titles_id, titles.nameas titles_name, titles.whatever as titles_whatever FROM "titles" >> INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY titles.id, >> titles.name, titles.whatever <http://titles.id> ORDER BY comments_count >> DESC >> >> Atenciosamente, >> >> *Carlos Figueiredo* >> >> >> On Tue, Jul 23, 2013 at 1:48 PM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >> > wrote: >> >>> Can you write the right (no pun intended) query here? Thanks >>> >>> >>> On Tue, Jul 23, 2013 at 12:36 PM, Carlos Figueiredo < >>> carlos.figueiredo87-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> Your query is wrong... >>>> You need group all columns you show that arent the result of an >>>> aggregate function... >>>> So your group would be group(''titles.*'') >>>> Em 22/07/2013 18:22, "yaw" <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> escreveu: >>>> >>>> Rails 4.0.0, Ruby 2.0 >>>>> >>>>> class Title < ... >>>>> ... >>>>> >>>>> has_many :comments >>>>> >>>>> def self.order_by_number_of_comments_descending >>>>> select(''titles.*, count(comments.id) AS comments_count''). >>>>> joins(:comments). >>>>> group(''titles.id''). >>>>> order(''comment_count DESC'') >>>>> end >>>>> >>>>> results in a malformed SQL on Postgres, >>>>> >>>>> >>>>> SELECT COUNT(*) AS count_all, titles.id AS titles_id FROM "titles" >>>>> INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP >>>>> BY titles.id ORDER BY comments_count DESC >>>>> >>>>> I''ve contacted @steveklabnik and he''d re-open an issue reporting this >>>>> bug. <https://github.com/rails/rails/issues/5588> In the meantime, >>>>> has anybody got around this? The SQL is all correct until you call >>>>> group. >>>>> Thanks for helping >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Ruby on Rails: Talk" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >>>>> . >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/rubyonrails-talk/5def0eff-649b-4e00-9b87-154f02b9f34d%40googlegroups.com >>>>> . >>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>> >>>>> >>>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ruby on Rails: Talk" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXsquwiLear7OOO3ZJ-r-wzoO499L8JAhOVCWLNQGLXyPQ%40mail.gmail.com >>>> . >>>> >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>> >>> >>> >>> -- >>> visit my blog @ yawboakye.blogspot.com | call me on +233242057831 >>> or +233273201210 >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDvcJkAuDiQHV9sH6%3DiaXdBz%3DAEZzxqrW0odBJi33Oyb%3Dw%40mail.gmail.com >>> . >>> >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXu-qYKESOxwvgTjM4%2BVxgfFr06x7hEFMHG5t9P8ub_n1A%40mail.gmail.com > . > > For more options, visit https://groups.google.com/groups/opt_out. > > >-- visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or +233273201210 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDut5NDvPiQc6Q7rC%2BU%3DjnDOpTSW2hEB2pQ3ezVQTSEfTQ%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Scott Ribe
2013-Jul-24 00:36 UTC
Re: Using :group with #count generating bad SQL in Postgres
On Jul 23, 2013, at 6:28 PM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> • During grouping, the normal SQL requirement is to group on a column that is on both tables. As far as I know, grouping can''t be done on two tables when they don''t a common column. In your group call, only titles.id would be useful. The rest won''tYou seem to be confusing the grouping with the join condition. The join requires 1 (usually, sometimes more) column common to both tables. The grouping must include all columns not used in the aggregate function. -- Scott Ribe scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org http://www.elevated-dev.com/ (303) 722-0567 voice -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4F79E8C6-3BB4-4FE0-A64C-7B55C92DF4E8%40elevated-dev.com. For more options, visit https://groups.google.com/groups/opt_out.
Yaw Boakye elGran
2013-Jul-24 10:32 UTC
Re: Using :group with #count generating bad SQL in Postgres
I think so, sorry for the misinformation. Thanks for the correction :) On Wed, Jul 24, 2013 at 12:36 AM, Scott Ribe <scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org>wrote:> On Jul 23, 2013, at 6:28 PM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > • During grouping, the normal SQL requirement is to group on a > column that is on both tables. As far as I know, grouping can''t be done on > two tables when they don''t a common column. In your group call, only > titles.id would be useful. The rest won''t > > You seem to be confusing the grouping with the join condition. The join > requires 1 (usually, sometimes more) column common to both tables. The > grouping must include all columns not used in the aggregate function. > > > -- > Scott Ribe > scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org > http://www.elevated-dev.com/ > (303) 722-0567 voice > > > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/4F79E8C6-3BB4-4FE0-A64C-7B55C92DF4E8%40elevated-dev.com > . > For more options, visit https://groups.google.com/groups/opt_out. > > >-- visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or +233273201210 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDtMnrjojcknr3JeFE9Y0h_-N2MjkXsB7Qt4kNKn2%2BG0kQ%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Yaw Boakye elGran
2013-Jul-24 10:38 UTC
Re: Using :group with #count generating bad SQL in Postgres
@Carlos this query still throws an exception: def self.order_by_number_of_comments_descending select(''titles.id, titles.title, titles.submitter_name, titles.submitter_email, titles.created_at, titles.updated_at, count( comments.id) AS comments_count''). joins(:comments). group(''titles.id, titles.title, titles.submitter_name, titles.submitter_email, titles.created_at, titles.updated_at''). order(''comments_count DESC'') end still complaining about not finding comments_count :/ I''m using *PostgreSQL 9.1.5* On Wed, Jul 24, 2013 at 10:32 AM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> I think so, sorry for the misinformation. Thanks for the correction :) > > > > > On Wed, Jul 24, 2013 at 12:36 AM, Scott Ribe <scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org>wrote: > >> On Jul 23, 2013, at 6:28 PM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> wrote: >> >> > • During grouping, the normal SQL requirement is to group on a >> column that is on both tables. As far as I know, grouping can''t be done on >> two tables when they don''t a common column. In your group call, only >> titles.id would be useful. The rest won''t >> >> You seem to be confusing the grouping with the join condition. The join >> requires 1 (usually, sometimes more) column common to both tables. The >> grouping must include all columns not used in the aggregate function. >> >> >> -- >> Scott Ribe >> scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org >> http://www.elevated-dev.com/ >> (303) 722-0567 voice >> >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/rubyonrails-talk/4F79E8C6-3BB4-4FE0-A64C-7B55C92DF4E8%40elevated-dev.com >> . >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > -- > visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or > +233273201210 >-- visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or +233273201210 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDts7UtP_7BMMn1G4qF9-p--XSnB7WM_RWFe2cGh-Sfnfg%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Yaw Boakye elGran
2013-Jul-24 10:40 UTC
Re: Using :group with #count generating bad SQL in Postgres
Error message: PG::Error: ERROR: column "comments_count" does not exist LINE 1: ...l, titles.created_at, titles.updated_at ORDER BY comments_c... ^ : SELECT COUNT(*) AS count_all, titles.id, titles.title, titles.submitter_name, titles.submitter_email, titles.created_at, titles.updated_at AS titles_id_titles_title_titles_submitter_name_titles_submitter_e FROM "titles" INNER JOIN "comments" ON "comments"."title_id" "titles"."id" GROUP BY titles.id, titles.title, titles.submitter_name, titles.submitter_email, titles.created_at, titles.updated_at ORDER BY comments_count DESC On Wed, Jul 24, 2013 at 10:38 AM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> @Carlos this query still throws an exception: > > def self.order_by_number_of_comments_descending > select(''titles.id, titles.title, titles.submitter_name, > titles.submitter_email, titles.created_at, titles.updated_at, count( > comments.id) AS comments_count''). > joins(:comments). > group(''titles.id, titles.title, titles.submitter_name, > titles.submitter_email, titles.created_at, titles.updated_at''). > order(''comments_count DESC'') > end > > > > still complaining about not finding comments_count :/ > > I''m using *PostgreSQL 9.1.5* > > > On Wed, Jul 24, 2013 at 10:32 AM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8@public.gmane.orgm > > wrote: > >> I think so, sorry for the misinformation. Thanks for the correction :) >> >> >> >> >> On Wed, Jul 24, 2013 at 12:36 AM, Scott Ribe <scott_ribe-ZCQMRMivIIdp9Kz+wMwdXQ@public.gmane.orgm >> > wrote: >> >>> On Jul 23, 2013, at 6:28 PM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> wrote: >>> >>> > • During grouping, the normal SQL requirement is to group on a >>> column that is on both tables. As far as I know, grouping can''t be done on >>> two tables when they don''t a common column. In your group call, only >>> titles.id would be useful. The rest won''t >>> >>> You seem to be confusing the grouping with the join condition. The join >>> requires 1 (usually, sometimes more) column common to both tables. The >>> grouping must include all columns not used in the aggregate function. >>> >>> >>> -- >>> Scott Ribe >>> scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org >>> http://www.elevated-dev.com/ >>> (303) 722-0567 voice >>> >>> >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/rubyonrails-talk/4F79E8C6-3BB4-4FE0-A64C-7B55C92DF4E8%40elevated-dev.com >>> . >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> >> -- >> visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or >> +233273201210 >> > > > > -- > visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or > +233273201210 >-- visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or +233273201210 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDu_wG%2BD3QsVQv0YoRMLdJwhT29kMT0znaFTp0vfrj0aXQ%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Carlos Figueiredo
2013-Jul-24 11:10 UTC
Re: Using :group with #count generating bad SQL in Postgres
Now I figured out what is the error... I dont know why... But rails changed the column name where you count froum comments_count to count_all... And you refer it on your order by statement using the alias you choose... I hope somone more experienced on rails help you fix it, but for now... U could do 2 fix... You can call the alias rails choose (count_all) on your order statement (ugly way to solve) Or you can call for count(*) without alias on your order statement (more practiced by dba... Less ugly to solve) Em 24/07/2013 07:40, "Yaw Boakye elGran" <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> escreveu:> Error message: > > PG::Error: ERROR: column "comments_count" does not exist > LINE 1: ...l, titles.created_at, titles.updated_at ORDER BY comments_c... > ^ > : SELECT COUNT(*) AS count_all, titles.id, titles.title, titles.submitter_name, titles.submitter_email, titles.created_at, titles.updated_at AS titles_id_titles_title_titles_submitter_name_titles_submitter_e FROM "titles" INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY titles.id, titles.title, titles.submitter_name, titles.submitter_email, titles.created_at, titles.updated_at ORDER BY comments_count DESC > > > > > On Wed, Jul 24, 2013 at 10:38 AM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8@public.gmane.orgm > > wrote: > >> @Carlos this query still throws an exception: >> >> def self.order_by_number_of_comments_descending >> select(''titles.id, titles.title, titles.submitter_name, >> titles.submitter_email, titles.created_at, titles.updated_at, count( >> comments.id) AS comments_count''). >> joins(:comments). >> group(''titles.id, titles.title, titles.submitter_name, >> titles.submitter_email, titles.created_at, titles.updated_at''). >> order(''comments_count DESC'') >> end >> >> >> >> still complaining about not finding comments_count :/ >> >> I''m using *PostgreSQL 9.1.5* >> >> >> On Wed, Jul 24, 2013 at 10:32 AM, Yaw Boakye elGran < >> yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> I think so, sorry for the misinformation. Thanks for the correction :) >>> >>> >>> >>> >>> On Wed, Jul 24, 2013 at 12:36 AM, Scott Ribe < >>> scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org> wrote: >>> >>>> On Jul 23, 2013, at 6:28 PM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>>> wrote: >>>> >>>> > • During grouping, the normal SQL requirement is to group on a >>>> column that is on both tables. As far as I know, grouping can''t be done on >>>> two tables when they don''t a common column. In your group call, only >>>> titles.id would be useful. The rest won''t >>>> >>>> You seem to be confusing the grouping with the join condition. The join >>>> requires 1 (usually, sometimes more) column common to both tables. The >>>> grouping must include all columns not used in the aggregate function. >>>> >>>> >>>> -- >>>> Scott Ribe >>>> scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org >>>> http://www.elevated-dev.com/ >>>> (303) 722-0567 voice >>>> >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ruby on Rails: Talk" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/rubyonrails-talk/4F79E8C6-3BB4-4FE0-A64C-7B55C92DF4E8%40elevated-dev.com >>>> . >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>> >>> >>> -- >>> visit my blog @ yawboakye.blogspot.com | call me on +233242057831or >>> +233273201210 >>> >> >> >> >> -- >> visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or >> +233273201210 >> > > > > -- > visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or > +233273201210 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDu_wG%2BD3QsVQv0YoRMLdJwhT29kMT0znaFTp0vfrj0aXQ%40mail.gmail.com > . > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXt%2BAw-Uks%2B-_bjOCzV5BW6ASAHK%3Dz6FKECSYNcuge20KQ%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Carlos Figueiredo
2013-Jul-24 11:19 UTC
Re: Using :group with #count generating bad SQL in Postgres
@Yaw, can you test if you change the way you call the count on postgres, rails still change the name of the column? Ex. Try using count(comments.id) or count(1) besides count(*) on your query and let me know what happens... Ps.: The ugly fix of my last email still works Em 24/07/2013 08:10, "Carlos Figueiredo" <carlos.figueiredo87-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> escreveu:> Now I figured out what is the error... > I dont know why... But rails changed the column name where you count froum > comments_count to count_all... And you refer it on your order by statement > using the alias you choose... > I hope somone more experienced on rails help you fix it, but for now... U > could do 2 fix... > > You can call the alias rails choose (count_all) on your order statement > (ugly way to solve) > Or you can call for count(*) without alias on your order statement (more > practiced by dba... Less ugly to solve) > Em 24/07/2013 07:40, "Yaw Boakye elGran" <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> escreveu: > >> Error message: >> >> >> PG::Error: ERROR: column "comments_count" does not exist >> LINE 1: ...l, titles.created_at, titles.updated_at ORDER BY comments_c... >> ^ >> : SELECT COUNT(*) AS count_all, titles.id, titles.title, titles.submitter_name, titles.submitter_email, titles.created_at, titles.updated_at AS titles_id_titles_title_titles_submitter_name_titles_submitter_e FROM "titles" INNER JOIN "comments" ON "comments"."title_id" = "titles"."id" GROUP BY titles.id, titles.title, titles.submitter_name, titles.submitter_email, titles.created_at, titles.updated_at ORDER BY comments_count DESC >> >> >> >> >> On Wed, Jul 24, 2013 at 10:38 AM, Yaw Boakye elGran < >> yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> @Carlos this query still throws an exception: >>> >>> def self.order_by_number_of_comments_descending >>> select(''titles.id, titles.title, titles.submitter_name, >>> titles.submitter_email, titles.created_at, titles.updated_at, count( >>> comments.id) AS comments_count''). >>> joins(:comments). >>> group(''titles.id, titles.title, titles.submitter_name, >>> titles.submitter_email, titles.created_at, titles.updated_at''). >>> order(''comments_count DESC'') >>> end >>> >>> >>> >>> still complaining about not finding comments_count :/ >>> >>> I''m using *PostgreSQL 9.1.5* >>> >>> >>> On Wed, Jul 24, 2013 at 10:32 AM, Yaw Boakye elGran < >>> yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> I think so, sorry for the misinformation. Thanks for the correction :) >>>> >>>> >>>> >>>> >>>> On Wed, Jul 24, 2013 at 12:36 AM, Scott Ribe < >>>> scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org> wrote: >>>> >>>>> On Jul 23, 2013, at 6:28 PM, Yaw Boakye elGran <yawboakye10-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>>>> wrote: >>>>> >>>>> > • During grouping, the normal SQL requirement is to group on a >>>>> column that is on both tables. As far as I know, grouping can''t be done on >>>>> two tables when they don''t a common column. In your group call, only >>>>> titles.id would be useful. The rest won''t >>>>> >>>>> You seem to be confusing the grouping with the join condition. The >>>>> join requires 1 (usually, sometimes more) column common to both tables. The >>>>> grouping must include all columns not used in the aggregate function. >>>>> >>>>> >>>>> -- >>>>> Scott Ribe >>>>> scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org >>>>> http://www.elevated-dev.com/ >>>>> (303) 722-0567 voice >>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Ruby on Rails: Talk" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm >>>>> . >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/rubyonrails-talk/4F79E8C6-3BB4-4FE0-A64C-7B55C92DF4E8%40elevated-dev.com >>>>> . >>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>> >>>>> >>>>> >>>> >>>> >>>> -- >>>> visit my blog @ yawboakye.blogspot.com | call me on +233242057831or >>>> +233273201210 >>>> >>> >>> >>> >>> -- >>> visit my blog @ yawboakye.blogspot.com | call me on +233242057831or >>> +233273201210 >>> >> >> >> >> -- >> visit my blog @ yawboakye.blogspot.com | call me on +233242057831 or >> +233273201210 >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/rubyonrails-talk/CAKwoQDu_wG%2BD3QsVQv0YoRMLdJwhT29kMT0znaFTp0vfrj0aXQ%40mail.gmail.com >> . >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CANPOtXtBgnTka7rGWN8tXqXOxe%3DYAdbbmzTdgGWEDunGbu5AAw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.