I have the following data:
|--------------------------------------------------------|
|USER | ID | DEVICEID | DATE |
|--------------------------------------------------------|
|7 | 14450 | aa6603ceef3b397c | 2016-08-03 10:19:14|
|--------------------------------------------------------|
|7 | 14457 | aa6603ceef3b397c | 2016-08-02 18:33:43|
|--------------------------------------------------------|
|7 | 14398 | 82c422272772e05a | 2016-06-07 09:56:55|
|--------------------------------------------------------|
|7 | 14399 | 82c422272772e05a | 2016-06-07 09:14:28|
|--------------------------------------------------------|
|249 | 14433 | 75da16fe9c4e480d | 2016-07-06 11:10:32|
|--------------------------------------------------------|
|249 | 14358 | 75da16fe9c4e480d | 2016-08-03 10:03:07|
|--------------------------------------------------------|
But I need to mount a query to get the following data:
|--------------------------------------------------------|
|USER | ID | DEVICEID | DATE |
|--------------------------------------------------------|
|7 | 14450 | aa6603ceef3b397c | 2016-08-03 10:19:14|
|--------------------------------------------------------|
|7 | 14398 | 82c422272772e05a | 2016-06-07 09:56:55|
|--------------------------------------------------------|
|249 | 14358 | 75da16fe9c4e480d | 2016-08-03 10:03:07|
|--------------------------------------------------------|
That is, I need to group by Usere DeviceID, taking what has the latest date, but I need to know the Id of it too, because I need more data that exists in this table and the idea was to use as a subquery. How could I do that?