I want to get the latest highscore, per user, per game. My current query isn't working.
I have a SQL DB like the following:
player(string) game(string) score(int) Date(Date) time(Time)
jake soccer 20 2016/02/26 10:00:00
jake chess 50 2016/02/26 10:00:00
jake soccer 40 2016/02/26 13:00:00
jake chess 30 2016/02/26 13:00:00
jake soccer 20 2016/02/26 15:00:00
jake chess 60 2016/02/26 15:00:00
jake soccer 80 2016/02/26 18:00:00
jake chess 10 2016/02/26 18:00:00
mike chess 30 2016/02/26 13:00:00
mike soccer 20 2016/02/26 15:00:00
mike chess 60 2016/02/26 15:00:00
mike soccer 80 2016/02/26 18:00:00
mike chess 10 2016/02/26 18:00:00
What I want to get out of it is:
jake soccer 80 2016/02/26 18:00:00
jake chess 10 2016/02/26 18:00:00
mike soccer 80 2016/02/26 18:00:00
mike chess 10 2016/02/26 18:00:00
I found out the Time column also has the date, so this should work. This is my current Query:
SELECT t1.*
FROM db t1
INNER JOIN (
SELECT player, MAX(time) TS
FROM db
GROUP BY player
) t2 ON t2.player = t1.player and t2.TS = t1.time
ORDER BY score DESC";
EDIT: I'm getting lots of wrong rows. Basically. I'm getting them sorted by time, but not the date I now need to sort them not only by MAX(Time) but MAX(Date) as well. Or merge Date and Time in a new var