2
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 whatever has the latest date, but I need to know his Id too, because I need more data that exists in this table and the idea was to use as subquery. How could I do that?
Thanks for the answer, I did something similar here but with the reverse thought of yours. I am only suspicious of having to use this comparison in LEFT JOIN without having the ID as a reference, because there is a very small (almost zero) chance that there are two records with the same date.
– Salatiel
I get it. Try it the way I reported it in the reply issue.
– Victor T.
Thanks, it helped a lot!
– Salatiel