I have a table "student_points".
id user_id points subject_id
1 10 45 22
2 11 75 23
3 12 78 24
4 10 13 23
5 12 65 23
and so on ...
This table contain about 1000 records of users and points. I want 10 records based on points (Max points first) So I can use mysql query as
Select * from student_points order by points limit 0,10
Now the requirement is that we need to group these 10 records based on user_id For example in first 10 records three are 3 students records so they should display in group. End result should be like
id user_id points subject_id
3 12 78 24
5 12 65 23
1 10 45 22
4 10 13 23
2 11 75 23
You can see that first record is based on most point and it student id is 12, now they are group according to user_id.
I tried two order by . I also tried to array_multisort after getting result but both are not working properly.
Please suggest any way, Either mysql query or group after getting result.
Thanks
user_idsorted by descending order of points?