Hi,

I tried to make query similar to Pratik's from his post:
http://m.onkey.org/2007/11/1/find-users-with-at-least-n-items

User.find :all, :joins => "INNER JOIN items ON items.user_id =
users.id", :select => "users.*, count(items.id) items_count", :group
=> "items.user_id HAVING items_count > 5"

I use postgresql and it keeps giving me errors while trying to make
such a query. I changed "count(items.id) items_count" to "count
(items.id) as items_count" and the missing thing is users.id (it must
be in group by). When I put users.id into group by it says that I must
put users.login in group by.

So I end up with query:
User.find :all, :joins => "INNER JOIN items ON items.user_id =
users.id", :select => "users.*, count(items.id) items_count", :group
=> "users.id, users.login, users.email, (.... listing all user
columns ....), items.user_id HAVING items_count > 5"

Listing all users columns is not best option... maybe someone more
familiar with SQL and postgresql could help me with this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to