Skip to content

Instantly share code, notes, and snippets.

@joshuaclayton
Created December 5, 2008 17:22
Show Gist options
  • Save joshuaclayton/32411 to your computer and use it in GitHub Desktop.
Save joshuaclayton/32411 to your computer and use it in GitHub Desktop.
SELECT s.*
FROM scores s
JOIN (
SELECT MAX(s1.score_value) AS score_value, s1.user_id
FROM scores s1
JOIN companies c1 ON c1.id = s1.company_id
WHERE s1.company_id = 8 AND s1.status = 'validated'
GROUP BY s1.user_id
) AS high_scores ON high_scores.user_id = s.user_id AND high_scores.score_value = s.score_value
WHERE s.company_id = 8 AND s.status = 'validated'
GROUP BY s.user_id
ORDER BY s.score_value DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment