Group by max date and id

Viewed 7868

I have the following table:

 id         value       date
 ---------  ---------  ----------
 1          324          2017-05-19 02:00:00
 2          564          2017-05-19 04:00:00
 3          675          2017-05-19 03:00:00
 3          642          2017-05-19 05:00:00
 4          642          2017-05-19 07:00:00
 5          642          2017-05-19 06:00:00
 6          642          2017-05-19 05:00:00
 6          642          2017-05-19 12:00:00
 7          642          2017-05-19 01:00:00
 8          642          2017-05-19 13:00:00
 8          642          2017-05-19 02:00:00

I want to GROUP BY the id column but also select the value and date column from the first row when ordered by date descending, with that id.

The result should be like this:

 id         value       date
 ---------  ---------  ----------
 1          324          2017-05-19 02:00:00
 2          564          2017-05-19 04:00:00
 3          642          2017-05-19 05:00:00
 4          642          2017-05-19 07:00:00
 5          642          2017-05-19 06:00:00
 6          642          2017-05-19 12:00:00
 7          642          2017-05-19 01:00:00
 8          642          2017-05-19 13:00:00
5 Answers
Related