Getting unique entries after creating a join in rails

named_scope :active_between, lambda { |start, fin| {:joins => [:contacts, :favourites], :conditions => ["?< contacts.created_at and contacts.created_at<? or ?<favourites.created_at and favourites.created_at<?",start, fin, start, fin],:select => "DISTINCT users.*"}}

Ok so this is a pretty ugly long query, but unfortunately it's necessary to use or statements in the query.

The problem I'm having is with the final piece of this code :select => "DISTINCT users.* because of the join it's returning the amount of times any user on the site does something, whereas I just want to know how many unique users are doing stuff within particular time frames.

Also tried :group_by => "users.*" and group => "users.*", I'm pretty new to Rails and SQL, any help would be greatly appreciated :slight_smile: