I’m trying to pull a query that will pull the top 20 unique “members” based on their top individual “report scores”. the problem is that if the top member’s 2nd best report score is also in the top 20, then the query only returns 19 members
top_members = Member.all(:joins=>[:reports], :conditions => ["score > 0"],:order => ["score DESC"],:limit => 20).uniq
what do i need to do get the query to keep going till i have 20 members?
Thanks!
At the moment you’re grabbing 20 results from the database and then discarding the duplicates when calling
uniq(). Instead you can select distinct results from the database, something like: