I have a table that holds the userID, highest score and a timestamp.
Sort by timestamp I would like, so that the latest entries are on the top, and also, do not show any user ID twice in the list, so they need to be grouped.
I also need to sort by
$ sql = "SELECT * $ DESC by user ID order by table group"; $ sql2 = "SELECT * FROM $ table group by user id order scores dsc";
At this time, I think that the group is done first, so I might get some random timestamps / tickets. I need to order them first, group them though, if I I want to order if I get errors.
Can anyone help me out here? Thanks
group
ing is always done before ORDER < / Code> ing To order a record before grouping, there are 2 approaches:
-
Apply subquery and then GROUP BY
in ORDER BY
. This is not usually a better way because running a sub-education is very expensive, especially if you have many records for small records, it's going to be okay.
$ sql = "Select * from (select * to $ table DESC at the time of ORDER) by group" URIID ";
-
There is a better solution for getting a maximum (time)
in a subquery and then userID < / Code> and maximum time.
SELECT p1 * From $ table T1 INNER JOIN (SELECT MAX (time) maxtime, $ User ID by $ table number) t2 ON. T1.userID = T2.userID and t1.time = t2.MaxTime command t1.time DESC;
I have written them from above my head.
HH
Comments
Post a Comment