Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a score model where users can play and add scores. When I pick the highscore I don't want to let users have more than one score on the scoreboard.

Therefore I need to sort the score by points and group/distinct on user_id. I have gotten all sorts of errors,

...must appear in the GROUP BY clause or be used in an aggregate function...

SELECT DISTINCT ON expressions must match initial ORDER BY expressions

This is my query:

Score.all(:select => "DISTINCT ON (user_id) *", :order_by => "points DESC")
share|improve this question
    
I think it's telling you to write distinct on (user_id, points) –  Denis Jun 1 '13 at 12:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.