My Database structure
Table 'Player' : column 'id'
Table 'Score' : column 'player_id' , 'score' , 'time'
example data in Table ‘Score’
player_id score time
1001 100 2000-01-01 00:00:00
1001 3 2012-08-01 00:00:00
1001 11 2012-08-02 00:00:00
1002 80 2012-07-01 00:00:00
1002 5 2012-08-01 00:00:00
1003 90 2012-07-01 00:00:00
I try to use
SELECT * FROM Score WHERE MONTH(time) = MONTH(NOW()) ORDER BY score DESC
The result from Player 1001 will be multiple row of score 11 and 3.
How to sort and get only max score in time length that should be only score 11 of Player 1001
The result should be
player_id score time
1001 11 2012-08-02 00:00:00
1002 5 2012-08-01 00:00:00
not
player_id score time
1001 11 2012-08-02 00:00:00
1001 3 2012-08-01 00:00:00
1002 5 2012-08-01 00:00:00
1 Answer