i want to select row by the highest votecount from a table, but if the userid is repeted i want the just the row with the highest votecount. eg:
userId | votecount |
---|---|
2 | 2 |
2 | 12 |
1 | 20 |
my result is supposed to be:
1,20
2,12
this is my current code:
SELECT * from `audio` GROUP BY `userId` ORDER BY `votecount` DESC LIMIT 50
the result of my code is :
1,20
2,2
it’s grouping by userId and then ordering it by votecount, which is not the desired output
2
Answers
If that’s the case and you don’t have a unique row id, you need to add the other columns in the group by clause